Passed
Pull Request — master (#82)
by Dmitriy
02:29
created

HeadersProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 3
c 1
b 0
f 0
dl 0
loc 29
ccs 6
cts 6
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAll() 0 3 1
A __construct() 0 3 1
A add() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ErrorHandler;
6
7
use Yiisoft\ErrorHandler\Middleware\ErrorCatcher;
8
9
/**
10
 * `HeadersProvider` provides headers for error response.
11
 * It is used by {@see ErrorCatcher} to add headers to response in case of error.
12
 */
13
final class HeadersProvider
14
{
15
    /**
16
     * @param array<string, string[]> $headers Default headers list.
17
     */
18 12
    public function __construct(
19
        private array $headers = [],
20
    ) {
21 12
    }
22
23
    /**
24
     * Adds a header to the list of headers.
25
     *
26
     * @param string $name The header name.
27
     * @param string|string[] $values The header value.
28
     */
29 1
    public function add(string $name, string|array $values): void
30
    {
31 1
        $this->headers[$name] = (array)$values;
32
    }
33
34
    /**
35
     * Returns all headers.
36
     *
37
     * @return array<string, string[]> The headers list.
38
     */
39 9
    public function getAll(): array
40
    {
41 9
        return $this->headers;
42
    }
43
}
44