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
Pull Request — master (#1)
by Ema
03:02
created

ApiClient::files()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pnz\MattermostClient;
6
7
use Http\Client\HttpClient;
8
use Http\Discovery\HttpClientDiscovery;
9
use Http\Discovery\MessageFactoryDiscovery;
10
use Http\Message\MessageFactory;
11
use Http\Message\RequestFactory;
12
use Pnz\MattermostClient\Api\Channels;
13
use Pnz\MattermostClient\Api\Files;
14
use Pnz\MattermostClient\Api\Posts;
15
use Pnz\MattermostClient\Api\Teams;
16
use Pnz\MattermostClient\Api\Users;
17
use Pnz\MattermostClient\Hydrator\Hydrator;
18
use Pnz\MattermostClient\Hydrator\ModelHydrator;
19
20
final class ApiClient
21
{
22
    /**
23
     * @var HttpClient
24
     */
25
    private $httpClient;
26
27
    /**
28
     * @var Hydrator
29
     */
30
    private $hydrator;
31
32
    /**
33
     * @var RequestFactory
34
     */
35
    private $messageFactory;
36
37
    /**
38
     * Construct an ApiClient instance.
39
     *
40
     * @param HttpClient|null     $httpClient     The HttpClient;  if null, the auto-discover will be used
41
     * @param MessageFactory|null $requestFactory The MessageFactory; if null, the auto-discover will be used
42
     * @param Hydrator|null       $hydrator       The Hydrator to use, default to the ModelHydrator
43
     */
44
    public function __construct(
45
        HttpClient $httpClient = null,
46
        MessageFactory $requestFactory = null,
47
        Hydrator $hydrator = null
48
    ) {
49
        $this->httpClient = $httpClient ?: HttpClientDiscovery::find();
50
        $this->messageFactory = $requestFactory ?: MessageFactoryDiscovery::find();
51
        $this->hydrator = $hydrator ?: new ModelHydrator();
52
    }
53
54
    /**
55
     * Returns configured ApiClient from the given Configurator, Hydrator and RequestFactory.
56
     *
57
     * @param HttpClientConfigurator $httpClientConfigurator
58
     * @param Hydrator|null          $hydrator
59
     * @param RequestFactory|null    $requestFactory
60
     *
61
     * @return ApiClient
62
     */
63
    public static function configure(
64
        HttpClientConfigurator $httpClientConfigurator,
65
        RequestFactory $requestFactory = null,
66
        Hydrator $hydrator = null
67
    ): self {
68
        $httpClient = $httpClientConfigurator->createConfiguredClient();
69
70
        return new self($httpClient, $requestFactory, $hydrator);
0 ignored issues
show
Bug introduced by
It seems like $requestFactory defined by parameter $requestFactory on line 65 can also be of type object<Http\Message\RequestFactory>; however, Pnz\MattermostClient\ApiClient::__construct() does only seem to accept null|object<Http\Message\MessageFactory>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
71
    }
72
73
    /**
74
     * Return a client handling the Users resources.
75
     *
76
     * @return Api\Users
77
     */
78
    public function users(): Users
79
    {
80
        return new Api\Users($this->httpClient, $this->messageFactory, $this->hydrator);
0 ignored issues
show
Compatibility introduced by
$this->messageFactory of type object<Http\Message\RequestFactory> is not a sub-type of object<Http\Message\MessageFactory>. It seems like you assume a child interface of the interface Http\Message\RequestFactory 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...
81
    }
82
83
    /**
84
     * Return a client handling the Teams resources.
85
     *
86
     * @return Api\Teams
87
     */
88
    public function teams(): Teams
89
    {
90
        return new Api\Teams($this->httpClient, $this->messageFactory, $this->hydrator);
0 ignored issues
show
Compatibility introduced by
$this->messageFactory of type object<Http\Message\RequestFactory> is not a sub-type of object<Http\Message\MessageFactory>. It seems like you assume a child interface of the interface Http\Message\RequestFactory 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...
91
    }
92
93
    /**
94
     * Return a client handling the Channels resources.
95
     *
96
     * @return Api\Channels
97
     */
98
    public function channels(): Channels
99
    {
100
        return new Api\Channels($this->httpClient, $this->messageFactory, $this->hydrator);
0 ignored issues
show
Compatibility introduced by
$this->messageFactory of type object<Http\Message\RequestFactory> is not a sub-type of object<Http\Message\MessageFactory>. It seems like you assume a child interface of the interface Http\Message\RequestFactory 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...
101
    }
102
103
    /**
104
     * Return a client handling the Posts resources.
105
     *
106
     * @return Api\Posts
107
     */
108
    public function posts(): Posts
109
    {
110
        return new Api\Posts($this->httpClient, $this->messageFactory, $this->hydrator);
0 ignored issues
show
Compatibility introduced by
$this->messageFactory of type object<Http\Message\RequestFactory> is not a sub-type of object<Http\Message\MessageFactory>. It seems like you assume a child interface of the interface Http\Message\RequestFactory 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...
111
    }
112
113
114
    /**
115
     * Return a client handling the Files resources.
116
     *
117
     * @return Api\Files
118
     */
119
    public function files(): Files
120
    {
121
        return new Api\Files($this->httpClient, $this->messageFactory, $this->hydrator);
0 ignored issues
show
Compatibility introduced by
$this->messageFactory of type object<Http\Message\RequestFactory> is not a sub-type of object<Http\Message\MessageFactory>. It seems like you assume a child interface of the interface Http\Message\RequestFactory 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...
122
    }
123
}
124