Completed
Pull Request — master (#275)
by Kristof
06:32
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
    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