Completed
Push — master ( aeb3a4...04afb5 )
by brian
01:57
created

Preference   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 0

Test Coverage

Coverage 100%
Metric Value
wmc 6
cbo 0
dl 0
loc 74
ccs 17
cts 17
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getVariant() 0 4 1
A getPrecedence() 0 4 1
A getQualityFactor() 0 4 1
A __toString() 0 8 2
1
<?php
2
3
/**
4
 * @copyright   (c) 2006-present brian ridley
5
 * @author      brian ridley <[email protected]>
6
 * @license     http://opensource.org/licenses/MIT MIT
7
 */
8
9
namespace ptlis\ConNeg\Preference;
10
11
/**
12
 * Value type storing variant preferences.
13
 */
14
class Preference implements PreferenceInterface
15
{
16
    /**
17
     * The variant name.
18
     *
19
     * @var string
20
     */
21
    private $variant;
22
23
    /**
24
     * The quality factor associated with this variant.
25
     *
26
     * @var float
27
     */
28
    private $qFactor;
29
30
    /**
31
     * Precedence of the variant (full > partial wildcard > wildcard > absent).
32
     *
33
     * @var int
34
     */
35
    protected $precedence;
36
37
38
    /**
39
     * Constructor
40
     *
41
     * @param string $variant
42
     * @param float $qFactor
43
     * @param int $precedence
44
     */
45 107
    public function __construct($variant, $qFactor, $precedence)
46
    {
47 107
        $this->variant = $variant;
48 107
        $this->qFactor = $qFactor;
49 107
        $this->precedence = $precedence;
50 107
    }
51
52
    /**
53
     * @inheritDoc
54
     */
55 79
    public function getVariant()
56
    {
57 79
        return $this->variant;
58
    }
59
60
    /**
61
     * @inheritDoc
62
     */
63 68
    public function getPrecedence()
64
    {
65 68
        return $this->precedence;
66
    }
67
68
    /**
69
     * @inheritDoc
70
     */
71 78
    public function getQualityFactor()
72
    {
73 78
        return $this->qFactor;
74
    }
75
76
    /**
77
     * @inheritDoc
78
     */
79 9
    public function __toString()
80
    {
81 9
        $str = '';
82 9
        if (strlen($this->getVariant())) {
83 9
            $str = $this->getVariant() . ';q=' . $this->getQualityFactor();
84 9
        }
85 9
        return $str;
86
    }
87
}
88