AbstractHeader   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 68
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A set() 0 7 1
A getFieldName() 0 4 1
A getFieldValue() 0 4 1
A __toString() 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
/**
14
 * @author      Iqbal Maulana <[email protected]>
15
 * @created     8/3/15
16
 */
17
abstract class AbstractHeader implements HeaderInterface
18
{
19
    use HeaderFactoryTrait;
20
21
    /**
22
     * @var string
23
     */
24
    private $value;
25
26
    /**
27
     * Constructor.
28
     *
29
     * @param string|null $value
30
     */
31
    public function __construct($value = null)
32
    {
33
        GenericHeader::assertEmptyHeaderFieldName(static::$headerName);
34
35
        if (null !== $value) {
36
            $this->set($value);
37
        }
38
    }
39
40
    /**
41
     * Set header value.
42
     *
43
     * @param string $value
44
     *
45
     * @return $this
46
     */
47
    public function set($value)
48
    {
49
        GenericHeader::assertHeaderValue($value);
50
        $this->value = $value;
51
52
        return $this;
53
    }
54
55
    /**
56
     * Get header field name.
57
     *
58
     * @return string
59
     */
60
    public function getFieldName()
61
    {
62
        return static::$headerName;
63
    }
64
65
    /**
66
     * Get header field value.
67
     *
68
     * @return mixed
69
     */
70
    public function getFieldValue()
71
    {
72
        return $this->value;
73
    }
74
75
    /**
76
     * Cast header to string.
77
     *
78
     * @return string
79
     */
80
    public function __toString()
81
    {
82
        return sprintf('%s: %s', $this->getFieldName(), $this->getFieldValue());
83
    }
84
}
85