Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
HibpHttp
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
3
 client
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Icawebdesign\Hibp;
6
7use GuzzleHttp\Client;
8use GuzzleHttp\ClientInterface;
9use Icawebdesign\Hibp\Traits\HibpConfig;
10
11class 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}