| Total Complexity | 10 |
| Total Lines | 64 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | class Header |
||
| 6 | { |
||
| 7 | /** @var array */ |
||
| 8 | protected $headers; |
||
| 9 | |||
| 10 | /** @var int|null */ |
||
| 11 | protected $nPlurals; |
||
| 12 | |||
| 13 | public function __construct(array $headers = array()) |
||
| 14 | { |
||
| 15 | $this->setHeaders($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 | public function setHeaders(array $headers) |
||
| 42 | { |
||
| 43 | $this->headers = $headers; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @return array |
||
| 48 | */ |
||
| 49 | public function asArray() |
||
| 50 | { |
||
| 51 | return $this->headers; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param string $headerName |
||
| 56 | * |
||
| 57 | * @return string|null |
||
| 58 | */ |
||
| 59 | protected function getHeaderValue($headerName) |
||
| 69 | } |
||
| 70 | } |
||
| 71 |