Passed
Pull Request — master (#82)
by Dmitriy
14:19 queued 11:46
created

HeadersProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
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 26
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 12
    public function __construct(
16
        private array $headers = [],
17
    ) {
18 12
    }
19
20
    /**
21
     * Adds a header to the list of headers.
22
     *
23
     * @param string $name The header name.
24
     * @param string|string[] $values The header value.
25
     */
26 1
    public function add(string $name, string|array $values): void
27
    {
28 1
        $this->headers[$name] = $values;
29
    }
30
31
    /**
32
     * Returns all headers.
33
     *
34
     * @return array<string, string|string[]> The headers list.
35
     */
36 9
    public function getAll(): array
37
    {
38 9
        return $this->headers;
39
    }
40
}
41