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

Age   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
c 1
b 0
f 1
dl 0
loc 24
ccs 9
cts 9
cp 1
rs 10
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
     * @return BaseHeaderValue
20
     */
21 18
    public function withValue($value): BaseHeaderValue
22
    {
23 18
        if (is_int($value)) {
24 3
            $value = (string)$value;
25
        }
26 18
        return parent::withValue($value);
27
    }
28
29 18
    protected function setValue(string $value): void
30
    {
31 18
        if (preg_match('/^\\d+$/', $value) !== 1) {
32 18
            $this->error = new ParsingException($value, 0, 'The value must consist of digits only.');
33
        } else {
34 6
            $this->error = null;
35
        }
36 18
        parent::setValue($value);
37 18
    }
38
}
39