AgeHeader   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 1
dl 0
loc 80
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A setDeltaSeconds() 0 6 1
A fromString() 0 7 2
A __toString() 0 4 1
A getFieldName() 0 4 1
A getFieldValue() 0 4 1
1
<?php
2
/*
3
 * This file is part of the Borobudur-Http package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Borobudur\Http\Header;
12
13
use Borobudur\Http\Header\Exception\InvalidHeaderValueException;
14
15
/**
16
 * @author      Iqbal Maulana <[email protected]>
17
 * @created     7/19/15
18
 */
19
class AgeHeader implements HeaderInterface
20
{
21
    /**
22
     * @var int
23
     */
24
    private $deltaSeconds;
25
26
    /**
27
     * Constructor.
28
     *
29
     * @param int|null $deltaSeconds
30
     */
31
    public function __construct($deltaSeconds = null)
32
    {
33
        if (null !== $deltaSeconds) {
34
            $this->setDeltaSeconds($deltaSeconds);
35
        }
36
    }
37
38
    /**
39
     * Set delta seconds.
40
     *
41
     * @param int $deltaSeconds
42
     *
43
     * @return $this
44
     *
45
     * @throws InvalidHeaderValueException
46
     */
47
    public function setDeltaSeconds($deltaSeconds)
48
    {
49
        $this->deltaSeconds = GenericHeader::computeDeltaSeconds($deltaSeconds);
50
51
        return $this;
52
    }
53
54
    /**
55
     * Factory create AgeHeader from string.
56
     *
57
     * @param string $headerLine
58
     *
59
     * @return $this
60
     */
61
    public static function fromString($headerLine)
62
    {
63
        list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine);
64
        GenericHeader::assertHeaderFieldName('Age', $fieldName);
65
66
        return new static($fieldValue !== null ? $fieldValue : null);
67
    }
68
69
    /**
70
     * Cast header to string.
71
     *
72
     * @return string
73
     */
74
    public function __toString()
75
    {
76
        return sprintf('%s: %s', $this->getFieldName(), $this->getFieldValue());
77
    }
78
79
    /**
80
     * Get header field name.
81
     *
82
     * @return string
83
     */
84
    public function getFieldName()
85
    {
86
        return 'Age';
87
    }
88
89
    /**
90
     * Get header field value.
91
     *
92
     * @return int
93
     */
94
    public function getFieldValue()
95
    {
96
        return $this->deltaSeconds;
97
    }
98
}
99