Passed
Pull Request — master (#2)
by mon
03:19
created

TypeParameter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 91
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getName() 0 4 1
A getValue() 0 4 1
A hasComment() 0 4 1
A getComment() 0 4 1
A toString() 0 8 2
1
<?php
2
3
namespace FileEye\MimeMap;
4
5
/**
6
 * Class for working with MIME type parameters.
7
 */
8
class TypeParameter
9
{
10
    /**
11
     * Parameter name.
12
     *
13
     * @var string
14
     */
15
    protected $name;
16
17
    /**
18
     * Parameter value.
19
     *
20
     * @var string
21
     */
22
    protected $value;
23
24
    /**
25
     * Parameter comment.
26
     *
27
     * @var string
28
     */
29
    protected $comment;
30
31
    /**
32
     * Constructor.
33
     *
34
     * @param string $name    Parameter name.
35
     * @param string $value   Parameter value.
36
     * @param string $comment Comment for this parameter.
37
     */
38 26
    public function __construct($name, $value, $comment = null)
39
    {
40 26
        $this->name = $name;
41 26
        $this->value = $value;
42 26
        $this->comment = $comment;
43 26
    }
44
45
    /**
46
     * Gets the parameter name.
47
     *
48
     * @return string
49
     */
50 23
    public function getName()
51
    {
52 23
        return $this->name;
53
    }
54
55
    /**
56
     * Gets the parameter value.
57
     *
58
     * @return string
59
     */
60 23
    public function getValue()
61
    {
62 23
        return $this->value;
63
    }
64
65
    /**
66
     * Does this parameter have a comment?
67
     *
68
     * @return boolean true if param has a comment, false otherwise.
69
     */
70 2
    public function hasComment()
71
    {
72 2
        return (bool) $this->comment;
73
    }
74
75
    /**
76
     * Gets the parameter comment.
77
     *
78
     * @return string
79
     */
80 22
    public function getComment()
81
    {
82 22
        return $this->comment;
83
    }
84
85
    /**
86
     * Gets a string representation of this parameter.
87
     *
88
     * @return string String representation of parameter.
89
     */
90 23
    public function toString()
91
    {
92 23
        $val = $this->name . '="' . str_replace('"', '\\"', $this->value) . '"';
93 23
        if ($this->comment) {
94 12
            $val .= ' (' . $this->comment . ')';
95
        }
96 23
        return $val;
97
    }
98
}
99