1 | <?php |
||
10 | abstract class AbstractHttpChecker extends AbstractChecker |
||
11 | { |
||
12 | /** |
||
13 | * The Guzzle HTTP client |
||
14 | * |
||
15 | * @var \GuzzleHttp\Client |
||
16 | */ |
||
17 | private $httpClient; |
||
18 | |||
19 | /** |
||
20 | * Guzzle options |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | private $guzzleOptions; |
||
25 | |||
26 | /** |
||
27 | * The URL that must be requested. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $url; |
||
32 | |||
33 | /** |
||
34 | * The method of the request. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $method = 'GET'; |
||
39 | |||
40 | /** |
||
41 | * Creates a new instance of this checker with a Guzzle HTTP client and options. |
||
42 | * |
||
43 | * @param \GuzzleHttp\Client $httpClient |
||
44 | * @param array $guzzleOptions |
||
45 | */ |
||
46 | public function __construct(Client $httpClient, array $guzzleOptions = []) |
||
51 | |||
52 | /** |
||
53 | * Requests the URL and handles any thrown exceptions. |
||
54 | * |
||
55 | * @return null |
||
56 | */ |
||
57 | public function run() |
||
77 | |||
78 | /** |
||
79 | * Maps a ConnectException into a CheckerHasFailed exception and throws it. |
||
80 | * |
||
81 | * @param \GuzzleHttp\Exception\ConnectException $exception |
||
82 | * |
||
83 | * @throws \Pbmedia\ApiHealth\Checkers\CheckerHasFailed |
||
84 | * @return null |
||
85 | */ |
||
86 | private function throwConnectException(ConnectException $exception) |
||
90 | |||
91 | /** |
||
92 | * Maps a Response into a CheckerHasFailed exception and throws it. |
||
93 | * |
||
94 | * @param \Psr\Http\Message\ResponseInterface $response |
||
95 | * |
||
96 | * @throws \Pbmedia\ApiHealth\Checkers\CheckerHasFailed |
||
97 | * @return null |
||
98 | */ |
||
99 | private function throwExceptionByResponse(ResponseInterface $response) |
||
103 | } |
||
104 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: