| Code Coverage
| Lines | Functions and Methods | Classes and Traits
Total | 100.00% covered (success) | 100.00% | 5 / 5 | 100.00% covered (success) | 100.00% | 3 / 3 | CRAP | 100.00% covered (success) | 100.00% | 1 / 1
DisplayHeaders | 100.00% covered (success) | 100.00% | 5 / 5 | 100.00% covered (success) | 100.00% | 3 / 3 | 4 | 100.00% covered (success) | 100.00% | 1 / 1
add | 100.00% covered (success) | 100.00% | 1 / 1 | 100.00% covered (success) | 100.00% | 1 / 1 | 1 |
getHeaderString | 100.00% covered (success) | 100.00% | 3 / 3 | 100.00% covered (success) | 100.00% | 1 / 1 | 2 |
displayInFile | 100.00% covered (success) | 100.00% | 1 / 1 | 100.00% covered (success) | 100.00% | 1 / 1 | 1 |

1 | <?php
2 | namespace Headers;
3 |
4 | use Headers\Interfaces\HeaderStringInterface;
5 |
6 | class DisplayHeaders implements HeaderStringInterface
7 | {
8 | protected array $headers = [];
9 |
10 | public function add(HeaderStringInterface $header): void
11 | {
12 | $this->headers[] = $header->getHeaderString();
13 | }
14 |
15 | public function getHeaderString(): string
16 | {
17 | if (count($this->headers) === 0) {
18 | throw new \Exception('There is no headers to display');
19 | }
20 | return implode("\n", $this->headers);
21 | }
22 |
23 | public function displayInFile(string $filePath): void
24 | {
25 | file_put_contents($filePath, implode("\n", $this->headers), FILE_APPEND);
26 | }
27 | }