GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Request::getRequestTarget()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 11
cts 11
cp 1
rs 9.2
cc 4
eloc 9
nc 5
nop 0
crap 4
1
<?php
2
/*
3
 * This file is part of the ReCaptcha Library.
4
 *
5
 * (c) Ilya Pokamestov <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
*/
10
11
namespace DS\Library\ReCaptcha\Http;
12
13
use InvalidArgumentException;
14
use Psr\Http\Message\RequestInterface;
15
use Psr\Http\Message\UriInterface;
16
17
/**
18
 * ReCaptcha library, PSR7 request representation.
19
 *
20
 * @author Ilya Pokamestov <[email protected]>
21
 *
22
 * Class Request
23
 * @package DS\Library\ReCaptcha\Http
24
 */
25
class Request extends Message implements RequestInterface
26
{
27
    /** @var string */
28
    protected $method;
29
    /** @var null|UriInterface */
30
    protected $uri;
31
    /** @var null|string */
32
    protected $requestTarget;
33
34
    /**
35
     * @param null|string $method HTTP method for the request.
36
     * @param null|string $uri URI for the request.
37
     *
38
     * @throws InvalidArgumentException for an invalid URI
39
     */
40 9
    public function __construct($method = null, $uri = null)
41
    {
42 9
        if (is_string($uri)) {
43 6
            $this->uri = new Uri($uri);
44 6
            $this->addHostHeader($this->uri);
45 9
        } elseif ($uri instanceof UriInterface) {
46 3
            $this->uri = $uri;
47 3
            $this->addHostHeader($this->uri);
48 3
        }
49
50 9
        if (is_string($method)) {
51 9
            $this->method = strtoupper($method);
52 9
        }
53 9
    }
54
55
    /**
56
     * Build host.
57
     *
58
     * @param UriInterface $uri
59
     */
60 9
    protected function addHostHeader(UriInterface $uri)
61
    {
62 9
        $host = $uri->getHost();
63 9
        if ($port = $uri->getPort()) {
64 1
            $host = sprintf('%s:%s', $host, $port);
65 1
        }
66
67 9
        $this->headers['host'] = array($host);
68 9
    }
69
70
    /** {@inheritdoc} */
71 1
    public function getRequestTarget()
72
    {
73 1
        if ($this->requestTarget !== null) {
74 1
            return $this->requestTarget;
75
        }
76
77 1
        $target = $this->uri->getPath();
78
79 1
        if ('' === $target) {
80 1
            $target = '/';
81 1
        }
82
83 1
        if ($this->uri->getQuery()) {
84 1
            $target .= '?' . $this->uri->getQuery();
85 1
        }
86
87 1
        return $target;
88
    }
89
90
    /** {@inheritdoc} */
91 1
    public function withRequestTarget($requestTarget)
92
    {
93 1
        if (preg_match('#\s#', $requestTarget)) {
94 1
            throw new InvalidArgumentException(
95
                'Invalid request target provided; cannot contain whitespace'
96 1
            );
97
        }
98 1
        $this->requestTarget = $requestTarget;
99
100 1
        return $this;
101
    }
102
103
    /** {@inheritdoc} */
104 3
    public function getMethod()
105
    {
106 3
        return $this->method;
107
    }
108
109
    /** {@inheritdoc} */
110 2
    public function withMethod($method)
111
    {
112 2
        $this->method = strtoupper($method);
113
114 2
        return $this;
115
    }
116
117
    /** {@inheritdoc} */
118 3
    public function getUri()
119
    {
120 3
        return $this->uri;
121
    }
122
123
    /** {@inheritdoc} */
124 2
    public function withUri(UriInterface $uri, $preserveHost = false)
125
    {
126 2
        $this->uri = $uri;
127
128 2
        if (!$preserveHost) {
129 2
            if ($uri->getHost()) {
130 2
                $this->addHostHeader($uri);
131 2
            }
132 2
        }
133
134 2
        return $this;
135
    }
136
}
137