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.

Response::__construct()   B
last analyzed

Complexity

Conditions 6
Paths 20

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 6

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 26
ccs 20
cts 20
cp 1
rs 8.439
cc 6
eloc 15
nc 20
nop 3
crap 6
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 Psr\Http\Message\ResponseInterface;
14
15
/**
16
 * ReCaptcha library, PSR7 response representation.
17
 *
18
 * @author Ilya Pokamestov <[email protected]>
19
 *
20
 * Class Response
21
 * @package DS\Library\ReCaptcha\Http
22
 */
23
class Response extends Message implements ResponseInterface
24
{
25
    /** @var null|string */
26
    protected $reasonPhrase = '';
27
    /** @var int */
28
    protected $statusCode = 200;
29
30
    /**
31
     * @param int    $status  Status code for the response, if any.
32
     * @param array  $headers Headers for the response, if any.
33
     * @param mixed  $body    Stream body.
34
     */
35 10
    public function __construct($status = 200, array $headers = array(), $body = null)
36
    {
37 10
        $this->statusCode = (int)$status;
38 10
        if ($body) {
39 5
            $this->stream = new Stream($body);
40 5
        }
41
42 10
        foreach ($headers as $headerName => $header) {
43
            //Some HTTP clients can provide header value in array format.
44 3
            if (is_array($header)) {
45 1
                $name = $headerName;
46 1
                $value = current($header);
47 1
            } else {
48 2
                list($name, $value) = explode(':', $header);
49
            }
50
51 3
            $values = explode(';', trim($value));
52 3
            foreach ($values as $headerValue) {
53 3
                $this->withAddedHeader($name, trim($headerValue));
54 3
            }
55 10
        }
56
57 10
        if (isset(Protocol::$phrases[$this->statusCode])) {
58 10
            $this->reasonPhrase = Protocol::$phrases[$this->statusCode];
59 10
        }
60 10
    }
61
62
    /** {@inheritdoc} */
63 3
    public function getStatusCode()
64
    {
65 3
        return $this->statusCode;
66
    }
67
68
    /** {@inheritdoc} */
69 2
    public function getReasonPhrase()
70
    {
71 2
        return $this->reasonPhrase;
72
    }
73
74
    /** {@inheritdoc} */
75 1
    public function withStatus($code, $reasonPhrase = '')
76
    {
77 1
        $this->statusCode = (int)$code;
78 1
        if (!$reasonPhrase && isset(Protocol::$phrases[$this->statusCode])) {
79 1
            $reasonPhrase = Protocol::$phrases[$this->statusCode];
80 1
        }
81 1
        $this->reasonPhrase = $reasonPhrase;
82
83 1
        return $this;
84
    }
85
}
86