Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
Config | |
100.00% |
11 / 11 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getSocketTimeout | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getStreamTimeout | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
withVirusFoundHeader | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
getVirusFoundHeader | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Ndrstmr\Icap; |
6 | |
7 | /** |
8 | * Transport and timeout configuration for the ICAP clients. |
9 | */ |
10 | final readonly class Config |
11 | { |
12 | /** |
13 | * @param string $host Hostname or IP of the ICAP server |
14 | * @param int $port TCP port, defaults to 1344 |
15 | * @param float $socketTimeout Timeout in seconds for establishing the connection |
16 | * @param float $streamTimeout Timeout in seconds for reading/writing |
17 | */ |
18 | public function __construct( |
19 | public string $host, |
20 | public int $port = 1344, |
21 | private float $socketTimeout = 10.0, |
22 | private float $streamTimeout = 10.0, |
23 | private string $virusFoundHeader = 'X-Virus-Name', |
24 | ) { |
25 | } |
26 | |
27 | /** |
28 | * Socket timeout in seconds. |
29 | */ |
30 | public function getSocketTimeout(): float |
31 | { |
32 | return $this->socketTimeout; |
33 | } |
34 | |
35 | /** |
36 | * Stream timeout in seconds. |
37 | */ |
38 | public function getStreamTimeout(): float |
39 | { |
40 | return $this->streamTimeout; |
41 | } |
42 | |
43 | /** |
44 | * Return a new instance with a different virus header. |
45 | */ |
46 | public function withVirusFoundHeader(string $headerName): self |
47 | { |
48 | return new self( |
49 | $this->host, |
50 | $this->port, |
51 | $this->socketTimeout, |
52 | $this->streamTimeout, |
53 | $headerName, |
54 | ); |
55 | } |
56 | |
57 | /** |
58 | * Header used by the ICAP server to report infections. |
59 | */ |
60 | public function getVirusFoundHeader(): string |
61 | { |
62 | return $this->virusFoundHeader; |
63 | } |
64 | } |