Completed
Push — master ( 6bd91f...3471cf )
by Luc
11s
created

Label::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
    /**
20
     * Label constructor.
21
     * @param string $value
22
     * @param bool $visible
23
     */
24
    public function __construct($value, $visible = true)
25
    {
26
        // Try constructing a LabelName object, so the same validation rules hold.
27
        $this->labelName = new LabelName($value);
28
29
        if (!is_bool($visible)) {
30
            throw new \InvalidArgumentException(sprintf(
31
                'Value for argument $visible should be a boolean, got a value of type %s.',
32
                gettype($visible)
33
            ));
34
        }
35
36
        $this->visible = $visible;
37
    }
38
39
    /**
40
     * @param Label $label
41
     * @return bool
42
     */
43
    public function equals(Label $label)
44
    {
45
        return strcmp(
46
            mb_strtolower((string) $this, 'UTF-8'),
47
            mb_strtolower((string) $label, 'UTF-8')
48
        ) == 0;
49
    }
50
51
    /**
52
     * @return boolean
53
     */
54
    public function isVisible()
55
    {
56
        return $this->visible;
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function __toString()
63
    {
64
        return $this->labelName->toNative();
65
    }
66
}
67