HeadersProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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 13
    public function __construct(
19
        private array $headers = [],
20
    ) {
21 13
    }
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 10
    public function getAll(): array
40
    {
41 10
        return $this->headers;
42
    }
43
}
44