Passed
Pull Request — master (#22)
by Aleksei
02:39
created

Age   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 1
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A withValue() 0 6 2
A setValue() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Http\Header\Value\Cache;
6
7
use Yiisoft\Http\Header\Parser\ParsingException;
8
use Yiisoft\Http\Header\Internal\BaseHeaderValue;
9
10
/**
11
 * @link https://tools.ietf.org/html/rfc7234#section-5.1
12
 */
13
final class Age extends BaseHeaderValue
14
{
15
    public const NAME = 'Age';
16
17
    /**
18
     * @param int|string $value
19
     *
20
     * @return BaseHeaderValue
21
     */
22 18
    public function withValue($value): BaseHeaderValue
23
    {
24 18
        if (is_int($value)) {
25 3
            $value = (string)$value;
26
        }
27 18
        return parent::withValue($value);
28
    }
29
30 18
    protected function setValue(string $value): void
31
    {
32 18
        if (preg_match('/^\\d+$/', $value) !== 1) {
33 18
            $this->error = new ParsingException($value, 0, 'The value must consist of digits only.');
34
        } else {
35 6
            $this->error = null;
36
        }
37 18
        parent::setValue($value);
38 18
    }
39
}
40