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.

RequestHandler::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
namespace JumpCloud\Handler;
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\Request\RequestInterface;
10
use JumpCloud\Response\ResponseInterface;
11
use Psr\Log\LoggerInterface;
12
use Psr\Log\NullLogger;
13
use Webmozart\Json\JsonEncoder;
14
15
/**
16
 * Class RequestHandler
17
 *
18
 * @package JumpCloud
19
 */
20
class RequestHandler
21
{
22
    /**
23
     * @var NullLogger
24
     */
25
    private $logger;
26
27
    /**
28
     * @var JsonEncoder
29
     */
30
    private $jsonEncoder;
31
32
    /**
33
     * RequestHandler constructor.
34
     *
35
     * @param LoggerInterface|null $logger
36
     */
37 15
    public function __construct(LoggerInterface $logger = null)
38
    {
39 15
        $this->logger = $logger ?: new NullLogger();
0 ignored issues
show
Documentation Bug introduced by
$logger ?: new \Psr\Log\NullLogger() is of type object<Psr\Log\LoggerInterface>, but the property $logger was declared to be of type object<Psr\Log\NullLogger>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
40 15
        $this->jsonEncoder = new JsonEncoder();
41 15
    }
42
43
    /**
44
     * @param GuzzleClient $client
45
     * @param RequestInterface $request
46
     * @return ResponseInterface
47
     */
48 13
    public function handle(GuzzleClient $client, RequestInterface $request)
49
    {
50
        try {
51 13
            $response = $client->send(
52 13
                new HttpRequest(
53 13
                    $request->getMethod(),
54 12
                    $request->getUri(),
55 12
                    $request->getHeaders(),
56 12
                    $this->jsonEncoder->encode($request->getBody())
57
                )
58
            );
59 7
        } catch (\Exception $e) {
60 7
            $this->logger->debug(
61 7
                sprintf('Exception thrown during Guzzle request'),
62
                [
63 7
                    'message' => $e->getMessage(),
64 7
                    'line' => $e->getLine(),
65 7
                    'file' => $e->getFile(),
66 7
                    'trace' => $e->getTraceAsString()
67
                ]
68
            );
69
70 7
            $response = new Response(500);
71
72 7
            if ($e instanceof ClientException) {
73 2
                $response = new Response(401);
74
            }
75
        }
76
77 13
        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...
78
    }
79
}
80