1 | <?php |
||
2 | namespace BretRZaun\StatusPage\Check; |
||
3 | |||
4 | use Exception; |
||
5 | use BretRZaun\StatusPage\Result; |
||
6 | use Psr\Http\Client\ClientInterface; |
||
7 | use Psr\Http\Client\ClientExceptionInterface; |
||
8 | |||
9 | class UrlCheck extends AbstractCheck |
||
10 | { |
||
11 | |||
12 | protected $url; |
||
13 | |||
14 | /** |
||
15 | * @var Client |
||
0 ignored issues
–
show
|
|||
16 | */ |
||
17 | protected $client; |
||
18 | |||
19 | /** |
||
20 | * UrlCheck constructor. |
||
21 | * |
||
22 | * @param string $label Label |
||
23 | * @param string $url URL to be tested |
||
24 | * @param ClientInterface $client HTTP-Client to use |
||
25 | */ |
||
26 | public function __construct(string $label, string $url, ClientInterface $client) |
||
27 | { |
||
28 | parent::__construct($label); |
||
29 | $this->url = $url; |
||
30 | $this->setHttpClient($client); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * set http client |
||
35 | */ |
||
36 | public function setHttpClient(ClientInterface $client): void |
||
37 | { |
||
38 | $this->client = $client; |
||
0 ignored issues
–
show
It seems like
$client of type Psr\Http\Client\ClientInterface is incompatible with the declared type BretRZaun\StatusPage\Check\Client of property $client .
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.. ![]() |
|||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Check URL |
||
43 | * |
||
44 | * @return Result |
||
45 | * @throws GuzzleException |
||
46 | */ |
||
47 | public function checkStatus(): Result |
||
48 | { |
||
49 | $result = new Result($this->label); |
||
50 | try { |
||
51 | $request = $this->client->createRequest('GET', $this->url); |
||
52 | $response = $this->client->sendRequest($request); |
||
53 | if ($response->getStatusCode() !== 200) { |
||
54 | $result->setError('HTTP status code for '.$this->url.' is '.$response->getStatusCode()); |
||
55 | } |
||
56 | } catch (ClientExceptionInterface $e) { |
||
57 | $result->setError('URL failed: '.$this->url); |
||
58 | } |
||
59 | return $result; |
||
60 | } |
||
61 | } |
||
62 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths