Passed
Push — master ( 616f10...3db985 )
by Alexandre
02:45
created

PlainTextRequestModifier   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 17
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A modify() 0 8 3
1
<?php
2
/**
3
 * php-guard/curl <https://github.com/php-guard/curl>
4
 * Copyright (C) 2018 by Alexandre Le Borgne <[email protected]>.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
namespace PhpGuard\Curl\RequestModifier;
21
22
use PhpGuard\Curl\Collection\Headers;
23
use PhpGuard\Curl\CurlRequest;
24
25
class PlainTextRequestModifier implements RequestModifierInterface
26
{
27
    /**
28
     * Modify a request.
29
     *
30
     * @param CurlRequest $request
31
     *
32
     * @return CurlRequest
33
     */
34 13
    public function modify(CurlRequest $request): CurlRequest
35
    {
36 13
        $headers = $request->getHeaders();
37 13
        if (is_string($request->getData()) && !isset($headers[Headers::CONTENT_TYPE])) {
38 5
            $headers[Headers::CONTENT_TYPE] = Headers::CONTENT_TYPE_TEXT_PLAIN;
39
        }
40
41 13
        return $request;
42
    }
43
}
44