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.

SimpleClient::send()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 38
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 38
ccs 28
cts 28
cp 1
rs 8.439
cc 6
eloc 24
nc 6
nop 1
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\Client;
12
13
use DS\Library\ReCaptcha\Http\Response;
14
use Psr\Http\Message\RequestInterface;
15
use Psr\Http\Message\ResponseInterface;
16
17
/**
18
 * ReCaptcha library, simple http file_get_content client.
19
 *
20
 * @author Ilya Pokamestov <[email protected]>
21
 *
22
 * Class SimpleClient
23
 * @package DS\Library\ReCaptcha\Http\Client
24
 */
25
class SimpleClient implements ClientInterface
26
{
27
    /**
28
     * @param RequestInterface $request
29
     * @return ResponseInterface
30
     */
31 1
    public function send(RequestInterface $request)
32
    {
33 1
        $headers = array();
34 1
        foreach ($request->getHeaders() as $name => $values) {
35 1
             $headers[] = sprintf('%s: %s', $name, implode(', ', $values));
36 1
        }
37
38
        $options = array(
39
            'http' => array(
40 1
                'header'  => implode("\r\n", $headers),
41 1
                'method'  => (string)$request->getMethod(),
42 1
                'content' => (string)$request->getBody(),
43 1
            ),
44 1
        );
45
46 1
        $response = file_get_contents(
47 1
            (string)$request->getUri(),
48 1
            false,
49 1
            stream_context_create($options)
50 1
        );
51
52 1
        $status = 400;
53 1
        $protocol = null;
54
55 1
        if (isset($http_response_header) && is_array($http_response_header)) {
56 1
            $statusLine = array_shift($http_response_header);
57 1
            $statusHeaderPattern = '#^HTTP/(?P<version>[1-9]\d*\.\d) (?P<status>[1-5]\d{2})(\s+(?P<reason>.+))?$#';
58 1
            if (preg_match($statusHeaderPattern, $statusLine, $matches)) {
59 1
                $status = $matches['status'];
60 1
                $protocol = $matches['version'];
61 1
            }
62 1
        }
63
64 1
        $response = new Response($status, $http_response_header, $response === false ? null : $response);
65 1
        $response->withProtocolVersion($protocol);
66
67 1
        return $response;
68
    }
69
}
70