HttpAttributesContainer::hasHeader()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Mikemirten\Bundle\JsonApiBundle\Response\Behaviour;
5
6
trait HttpAttributesContainer
7
{
8
    /**
9
     * Status code
10
     *
11
     * @var int
12
     */
13
    protected $statusCode = 200;
14
15
    /**
16
     * Response headers
17
     *
18
     * @var array
19
     */
20
    protected $headers = [];
21
22
    /**
23
     * Set status code
24
     *
25
     * @param  int $code
26
     * @return mixed
27
     */
28 1
    public function setStatusCode(int $code)
29
    {
30 1
        $this->statusCode = $code;
31 1
    }
32
33
    /**
34
     * Get status code
35
     *
36
     * @return int
37
     */
38 4
    public function getStatusCode(): int
39
    {
40 4
        return $this->statusCode;
41
    }
42
43
    /**
44
     * Set header
45
     *
46
     * @param  string $name
47
     * @param  string $value
48
     * @return mixed
49
     */
50 1
    public function setHeader(string $name, string $value)
51
    {
52 1
        $this->headers[$name] = $value;
53 1
    }
54
55
    /**
56
     * Set headers
57
     *
58
     * @param array $headers
59
     */
60 1
    public function setHeaders(array $headers)
61
    {
62 1
        foreach ($headers as $name => $value)
63
        {
64 1
            $this->headers[$name] = $value;
65
        }
66 1
    }
67
68
    /**
69
     * Has header ?
70
     *
71
     * @param  string $name
72
     * @return bool
73
     */
74 1
    public function hasHeader(string $name): bool
75
    {
76 1
        return isset($this->headers[$name]);
77
    }
78
79
    /**
80
     * Get response headers
81
     *
82
     * @return array
83
     */
84 6
    public function getHeaders(): array
85
    {
86 6
        return $this->headers;
87
    }
88
}