UserAgentHeader   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A fromString() 0 8 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     7/28/15
16
 */
17
class UserAgentHeader implements HeaderInterface
18
{
19
    /**
20
     * @var string
21
     */
22
    private $value;
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param string|null $value
28
     */
29
    public function __construct($value = null)
30
    {
31
        if (null !== $value) {
32
            GenericHeader::assertHeaderValue($value);
33
            $this->value = $value;
34
        }
35
    }
36
37
    /**
38
     * Factory create UserAgentHeader from string representation.
39
     *
40
     * @param string $headerLine
41
     *
42
     * @return $this
43
     */
44
    public static function fromString($headerLine)
45
    {
46
        list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine);
47
        $fieldName = str_replace(array(' ', '_', '.'), '-', $fieldName);
48
        GenericHeader::assertHeaderFieldName('User-Agent', $fieldName);
49
50
        return new static($fieldValue);
51
    }
52
53
    /**
54
     * Get header field name.
55
     *
56
     * @return string
57
     */
58
    public function getFieldName()
59
    {
60
        return 'User-Agent';
61
    }
62
63
    /**
64
     * Get header field value.
65
     *
66
     * @return mixed
67
     */
68
    public function getFieldValue()
69
    {
70
        return $this->value;
71
    }
72
73
    /**
74
     * Cast header to string.
75
     *
76
     * @return string
77
     */
78
    public function __toString()
79
    {
80
        return sprintf('%s: %s', $this->getFieldName(), $this->getFieldValue());
81
    }
82
}
83