AbstractContentHeader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 60
rs 10
c 1
b 0
f 0

4 Methods

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