Completed
Pull Request — master (#275)
by Kristof
06:32
created

Label   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 52
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 2
A equals() 0 7 1
A isVisible() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
namespace CultuurNet\UDB3;
4
5
use CultuurNet\UDB3\Label\ValueObjects\LabelName;
6
7
class Label
8
{
9
    /**
10
     * @var LabelName
11
     */
12
    protected $labelName;
13
14
    /**
15
     * @var bool
16
     */
17
    protected $visible;
18
19
    public function __construct($value, $visible = true)
20
    {
21
        // Try constructing a LabelName object, so the same validation rules hold.
22
        $this->labelName = new LabelName($value);
23
24
        if (!is_bool($visible)) {
25
            throw new \InvalidArgumentException(sprintf(
26
                'Value for argument $visible should be a boolean, got a value of type %s.',
27
                gettype($visible)
28
            ));
29
        }
30
31
        $this->visible = $visible;
32
    }
33
34
    /**
35
     * @param Label $label
36
     * @return bool
37
     */
38
    public function equals(Label $label)
39
    {
40
        return strcmp(
41
            mb_strtolower((string) $this, 'UTF-8'),
42
            mb_strtolower((string) $label, 'UTF-8')
43
        ) == 0;
44
    }
45
46
    /**
47
     * @return boolean
48
     */
49
    public function isVisible()
50
    {
51
        return $this->visible;
52
    }
53
54
    public function __toString()
55
    {
56
        return $this->labelName->toNative();
57
    }
58
}
59