LocalizedName::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
namespace OpenConext\Value\Saml\Metadata\Common;
4
5
use OpenConext\Value\Assert\Assertion;
6
use OpenConext\Value\Serializable;
7
8
final class LocalizedName implements Serializable
9
{
10
    /**
11
     * @var string
12
     */
13
    private $name;
14
15
    /**
16
     * @var string
17
     */
18
    private $language;
19
20
    /**
21
     * @param string $name
22
     * @param string $language
23
     */
24
    public function __construct($name, $language)
25
    {
26
        Assertion::nonEmptyString($name, 'name');
27
        Assertion::nonEmptyString($language, 'language');
28
29
        $this->name = $name;
30
        $this->language = $language;
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    public function getName()
37
    {
38
        return $this->name;
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function getLanguage()
45
    {
46
        return $this->language;
47
    }
48
49
    /**
50
     * @param LocalizedName $other
51
     * @return bool
52
     */
53
    public function equals(LocalizedName $other)
54
    {
55
        return $this->name === $other->name && $this->language === $other->language;
56
    }
57
58
    public static function deserialize($data)
59
    {
60
        Assertion::isArray($data);
61
        Assertion::keysExist($data, array('name', 'language'));
62
63
        return new self($data['name'], $data['language']);
64
    }
65
66
    public function serialize()
67
    {
68
        return array(
69
            'name' => $this->name,
70
            'language' => $this->language
71
        );
72
    }
73
74
    public function __toString()
75
    {
76
        return sprintf('LocalizedName(name=%s, language=%s)', $this->name, $this->language);
77
    }
78
}
79