Passed
Pull Request — master (#27)
by Anatoly
39:10
created

AccessControlAllowMethodsHeader::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Nekhay <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Nekhay
8
 * @license https://github.com/sunrise-php/http-message/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-message
10
 */
11
12
namespace Sunrise\Http\Message\Header;
13
14
/**
15
 * Import classes
16
 */
17
use Sunrise\Http\Message\Exception\InvalidHeaderValueException;
18
use Sunrise\Http\Message\Header;
19
20
/**
21
 * Import functions
22
 */
23
use function implode;
24
use function strtoupper;
25
26
/**
27
 * @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods
28
 */
29
class AccessControlAllowMethodsHeader extends Header
30
{
31
32
    /**
33
     * @var list<string>
0 ignored issues
show
Bug introduced by
The type Sunrise\Http\Message\Header\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
     */
35
    private array $methods = [];
36
37
    /**
38
     * Constructor of the class
39
     *
40
     * @param string ...$methods
41
     *
42
     * @throws InvalidHeaderValueException
43
     *         If one of the methods isn't valid.
44
     */
45 11
    public function __construct(string ...$methods)
46
    {
47
        /** @var list<string> $methods */
48
49 11
        $this->validateToken(...$methods);
50
51
        // normalize the list of methods...
52 7
        foreach ($methods as $method) {
53 7
            $this->methods[] = strtoupper($method);
54
        }
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 7
    public function getFieldName(): string
61
    {
62 7
        return 'Access-Control-Allow-Methods';
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 5
    public function getFieldValue(): string
69
    {
70 5
        return implode(', ', $this->methods);
71
    }
72
}
73