Request   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 57.58 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 19
loc 33
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 19 20 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nyholm\Psr7;
6
7
use Psr\Http\Message\{RequestInterface, StreamInterface, UriInterface};
8
9
/**
10
 * @author Tobias Nyholm <[email protected]>
11
 * @author Martijn van der Ven <[email protected]>
12
 */
13
final class Request implements RequestInterface
14
{
15
    use MessageTrait;
16
    use RequestTrait;
17
18
    /**
19
     * @param string $method HTTP method
20
     * @param string|UriInterface $uri URI
21
     * @param array $headers Request headers
22
     * @param string|resource|StreamInterface|null $body Request body
23
     * @param string $version Protocol version
24
     */
25 73 View Code Duplication
    public function __construct(string $method, $uri, array $headers = [], $body = null, string $version = '1.1')
26
    {
27 73
        if (!($uri instanceof UriInterface)) {
28 71
            $uri = new Uri($uri);
29
        }
30
31 72
        $this->method = $method;
32 72
        $this->uri = $uri;
33 72
        $this->setHeaders($headers);
34 72
        $this->protocol = $version;
35
36 72
        if (!$this->hasHeader('Host')) {
37 71
            $this->updateHostFromUri();
38
        }
39
40
        // If we got no body, defer initialization of the stream until Request::getBody()
41 72
        if ('' !== $body && null !== $body) {
42 4
            $this->stream = Stream::create($body);
43
        }
44 72
    }
45
}
46