Passed
Push — master ( 39a5d6...80e6cc )
by Sebastian
10:40
created

AcceptHeader::getQuality()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @package Application Utils
4
 * @subpackage Request
5
 * @see \AppUtils\Request\AcceptHeader
6
 */
7
8
declare(strict_types=1);
9
10
namespace AppUtils\Request;
11
12
use ArrayAccess;
13
14
/**
15
 * Holds the information on an "Accept" header.
16
 * Can be accessed like an array.
17
 *
18
 * @package Application Utils
19
 * @subpackage Request
20
 * @author Sebastian Mordziol <[email protected]>
21
 * @implements ArrayAccess<string,mixed>
22
 */
23
class AcceptHeader implements ArrayAccess
24
{
25
    /**
26
     * @var array{type:string,pos:int,quality:float,params:array<string,string>}
27
     */
28
    private array $data;
29
30
    /**
31
     * @param string $type
32
     * @param int $position
33
     * @param array<string,string> $parameters
34
     * @param float $quality
35
     */
36
    public function __construct(string $type, int $position, array $parameters, float $quality)
37
    {
38
        $this->data = array(
39
            'type' => $type,
40
            'pos' => $position,
41
            'params' => $parameters,
42
            'quality' => $quality
43
        );
44
    }
45
46
    public function getMimeType() : string
47
    {
48
        return $this->data['type'];
49
    }
50
51
    public function getPosition() : int
52
    {
53
        return $this->data['pos'];
54
    }
55
56
    /**
57
     * @return array<string,string>
58
     */
59
    public function getParameters() : array
60
    {
61
        return $this->data['params'];
62
    }
63
64
    public function getQuality() : float
65
    {
66
        return $this->data['quality'];
67
    }
68
69
    /**
70
     * @param mixed $offset
71
     * @return bool
72
     */
73
    public function offsetExists($offset) : bool
74
    {
75
        return isset($this->data[$offset]);
76
    }
77
78
    /**
79
     * @param mixed $offset
80
     * @return array<string,string>|int|float|string
81
     */
82
    public function offsetGet($offset)
83
    {
84
        return $this->data[$offset] ?? null;
85
    }
86
87
    /**
88
     * @param mixed $offset
89
     * @param mixed $value
90
     * @return void
91
     */
92
    public function offsetSet($offset, $value) : void
93
    {
94
        if(isset($this->data[$offset]) && gettype($this->data[$offset]) === gettype($value)) {
95
            $this->data[$offset] = $value;
96
        }
97
    }
98
99
    /**
100
     * @param mixed $offset
101
     * @return void
102
     */
103
    public function offsetUnset($offset) : void
104
    {
105
        // nope
106
    }
107
}
108