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.
Passed
Pull Request — master (#2)
by Harald
02:47
created

Caller::getHttpClient()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0625
1
<?php
2
3
namespace Bokbasen\ApiClient;
4
5
use Bokbasen\ApiClient\Exceptions\BokbasenApiClientException;
6
use Http\Client\HttpClient;
7
use Http\Discovery\Psr17FactoryDiscovery;
8
use Http\Discovery\Psr18ClientDiscovery;
9
use Http\Message\StreamFactory;
10
use Psr\Http\Client\ClientExceptionInterface;
11
use Psr\Http\Client\ClientInterface;
12
use Psr\Http\Message\RequestFactoryInterface;
13
use Psr\Http\Message\ResponseInterface;
14
use Psr\Http\Message\StreamInterface;
15
use Psr\Http\Message\UriInterface;
16
17
class Caller
18
{
19
    /**
20
     * @var HttpClient
21
     */
22
    private $httpClient;
23
24
    /**
25
     * @var StreamFactory
26
     */
27
    private $streamFactory;
28
29
    /**
30
     * @var RequestFactoryInterface
31
     */
32
    private $requestFactory;
33
34 14
    public function __construct(
35
        ClientInterface $httpClient = null,
36
        RequestFactoryInterface $requestFactory = null,
37
        StreamInterface $streamFactory = null
38
    ) {
39 14
        $this->httpClient = $httpClient ?: Psr18ClientDiscovery::find();
0 ignored issues
show
Documentation Bug introduced by
$httpClient ?: Http\Disc...ClientDiscovery::find() is of type Psr\Http\Client\ClientInterface, but the property $httpClient was declared to be of type Http\Client\HttpClient. 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 14
        $this->requestFactory = $requestFactory ?: Psr17FactoryDiscovery::findRequestFactory();
41 14
        $this->streamFactory = $streamFactory ?: Psr17FactoryDiscovery::findStreamFactory();
0 ignored issues
show
Documentation Bug introduced by
It seems like $streamFactory ?: Http\D...ry::findStreamFactory() of type Psr\Http\Message\StreamFactoryInterface or Psr\Http\Message\StreamInterface is incompatible with the declared type Http\Message\StreamFactory of property $streamFactory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
42 14
    }
43
44
    /**
45
     * @param string                               $method
46
     * @param string|UriInterface                  $url
47
     * @param array                                $headers
48
     * @param resource|string|StreamInterface|null $body
49
     *
50
     * @return ResponseInterface
51
     *
52
     * @throws BokbasenApiClientException
53
     */
54 14
    public function request(string $method, $url, array $headers = [], $body = null): ResponseInterface
55
    {
56
        try {
57 14
            $request = $this->requestFactory->createRequest($method, $url);
58
59 14
            if (!empty($headers)) {
60 14
                foreach ($headers as $name => $value) {
61 14
                    $request = $request->withHeader($name, $value);
62
                }
63
            }
64
65 14
            if ($body !== null) {
66 10
                $request = $request->withBody(
67 10
                    $this->streamFactory->createStream($body)
68
                );
69
            }
70
71 14
            return $this->httpClient->sendRequest($request);
72 2
        } catch (ClientExceptionInterface | \Exception $e) {
73 2
            throw new BokbasenApiClientException($e->getMessage(), $e->getCode(), $e);
74
        }
75
    }
76
77 14
    public function setHttpClient(ClientInterface $httpClient): void
78
    {
79 14
        $this->httpClient = $httpClient;
0 ignored issues
show
Documentation Bug introduced by
$httpClient is of type Psr\Http\Client\ClientInterface, but the property $httpClient was declared to be of type Http\Client\HttpClient. 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...
80 14
    }
81
}
82