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.
Completed
Push — develop ( 71dad4...415593 )
by Gavin
05:32
created

RequestHandler::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 1
1
<?php
2
3
namespace JumpCloud\Request;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
use GuzzleHttp\Exception\ClientException;
7
use GuzzleHttp\Psr7\Request as HttpRequest;
8
use GuzzleHttp\Psr7\Response;
9
use JumpCloud\Response\ResponseInterface;
10
use Psr\Log\LoggerInterface;
11
use Psr\Log\NullLogger;
12
13
/**
14
 * Class RequestHandler
15
 *
16
 * @package JumpCloud
17
 */
18
class RequestHandler
19
{
20
    /** @var LoggerInterface */
21
    private $logger;
22
23
    /**
24
     * RequestHandler constructor.
25
     *
26
     * @param LoggerInterface|null $logger
27
     */
28
    public function __construct(LoggerInterface $logger = null)
29
    {
30
        $this->logger = $logger ?: new NullLogger();
31
    }
32
33
    /**
34
     * @param GuzzleClient $client
35
     * @param RequestInterface $request
36
     * @return ResponseInterface
37
     */
38
    public function handle(GuzzleClient $client, RequestInterface $request)
39
    {
40
        try {
41
            $response = $client->send(
42
                new HttpRequest(
43
                    $request->getMethod(),
44
                    $request->getUri(),
45
                    $request->getHeaders(),
46
                    \GuzzleHttp\json_encode($request->getBody())
0 ignored issues
show
Documentation introduced by
$request->getBody() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47
                )
48
            );
49
        } catch (\Exception $e) {
50
            $this->logger->debug(
51
                sprintf('Exception thrown during Guzzle request'),
52
                [
53
                    'message' => $e->getMessage(),
54
                    'line' => $e->getLine(),
55
                    'file' => $e->getFile(),
56
                    'trace' => $e->getTraceAsString()
57
                ]
58
            );
59
60
            $response = new Response(500);
61
62
            if ($e instanceof ClientException) {
63
                $response = new Response(401);
64
            }
65
        }
66
67
        return $request->getResponseFactory()->create($response);
0 ignored issues
show
Compatibility introduced by
$response of type object<Psr\Http\Message\ResponseInterface> is not a sub-type of object<GuzzleHttp\Psr7\Response>. It seems like you assume a concrete implementation of the interface Psr\Http\Message\ResponseInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
68
    }
69
}
70