Total Complexity | 9 |
Total Lines | 59 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
5 | class Header |
||
6 | { |
||
7 | /** @var array */ |
||
8 | protected $headers; |
||
9 | |||
10 | /** @var int|null */ |
||
11 | protected $nPlurals = null; |
||
12 | |||
13 | public function __construct(array $headers = array()) |
||
14 | { |
||
15 | $this->headers = $headers; |
||
16 | } |
||
17 | |||
18 | public function getPluralFormsCount() |
||
19 | { |
||
20 | if ($this->nPlurals !== null) { |
||
21 | return $this->nPlurals; |
||
22 | } |
||
23 | |||
24 | $header = $this->getHeaderValue('Plural-Forms'); |
||
25 | if ($header === null) { |
||
26 | $this->nPlurals = 0; |
||
27 | return $this->nPlurals; |
||
28 | } |
||
29 | |||
30 | $matches = array(); |
||
31 | if (preg_match('/nplurals=([0-9]+)/', $header, $matches) !== 1) { |
||
32 | $this->nPlurals = 0; |
||
33 | return $this->nPlurals; |
||
34 | } |
||
35 | |||
36 | $this->nPlurals = isset($matches[1]) ? (int)$matches[1] : 0; |
||
37 | |||
38 | return $this->nPlurals; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @return array |
||
43 | */ |
||
44 | public function asArray() |
||
45 | { |
||
46 | return $this->headers; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $headerName |
||
51 | * |
||
52 | * @return string|null |
||
53 | */ |
||
54 | protected function getHeaderValue($headerName) |
||
64 | } |
||
65 | } |
||
66 |