Lines
100.00%
12 / 12
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| HibpHttp | 100.00% | 12 / 12 | 100.00% | 2 / 2 | 4 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 11 / 11 | 100.00% | 1 / 1 | 3 | |||||
| client | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Icawebdesign\Hibp; | |
| 6 | ||
| 7 | use GuzzleHttp\Client; | |
| 8 | use GuzzleHttp\ClientInterface; | |
| 9 | use Icawebdesign\Hibp\Traits\HibpConfig; | |
| 10 | ||
| 11 | class HibpHttp | |
| 12 | { | |
| 13 | use HibpConfig; | |
| 14 | ||
| 15 | protected ClientInterface $client; | |
| 16 | ||
| 17 | public function __construct(?string $apiKey = null, ?ClientInterface $client = null) | |
| 18 | { | |
| 19 | $headers = [ | |
| 20 | 'User-Agent' => $this->userAgent, | |
| 21 | ]; | |
| 22 | ||
| 23 | if ($apiKey !== null) { | |
| 24 | $headers['hibp-api-key'] = $apiKey; | |
| 25 | } | |
| 26 | ||
| 27 | if ($client !== null) { | |
| 28 | $this->client = $client; | |
| 29 | ||
| 30 | return; | |
| 31 | } | |
| 32 | ||
| 33 | $this->client = new Client([ | |
| 34 | 'headers' => $headers, | |
| 35 | ]); | |
| 36 | } | |
| 37 | ||
| 38 | public function client(): ClientInterface | |
| 39 | { | |
| 40 | return $this->client; | |
| 41 | } | |
| 42 | } |