EntityType::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
namespace OpenConext\Value\Saml;
4
5
use OpenConext\Value\Assert\Assertion;
6
use OpenConext\Value\Serializable;
7
8
final class EntityType implements Serializable
9
{
10
    const TYPE_SP  = 'saml20-sp';
11
    const TYPE_IDP = 'saml20-idp';
12
13
    /**
14
     * @var string
15
     */
16
    private $type;
17
18
    /**
19
     * @param string $type
20
     */
21
    public function __construct($type)
22
    {
23
        Assertion::inArray(
24
            $type,
25
            array(self::TYPE_SP, self::TYPE_IDP),
26
            'EntityType must be one of EntityType::TYPE_SP or EntityType::TYPE_IDP'
27
        );
28
29
        $this->type = $type;
30
    }
31
32
    /**
33
     * Creates a new ServiceProvider Type
34
     * @return EntityType
35
     *
36
     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
37
     * @SuppressWarnings(PHPMD.ShortMethodName)
38
     */
39
    public static function SP()
40
    {
41
        return new EntityType(self::TYPE_SP);
42
    }
43
44
    // @codingStandardsIgnoreStart
45
    /**
46
     * Creates a new IdentityProvider Type
47
     * @return EntityType
48
     *
49
     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
50
     */
51
    public static function IdP()
52
    {
53
        return new EntityType(self::TYPE_IDP);
54
    }
55
    // @codingStandardsIgnoreEnd
56
57
    /**
58
     * @return bool
59
     */
60
    public function isServiceProvider()
61
    {
62
        return $this->type === self::TYPE_SP;
63
    }
64
65
    /**
66
     * @return bool
67
     */
68
    public function isIdentityProvider()
69
    {
70
        return $this->type === self::TYPE_IDP;
71
    }
72
73
    /**
74
     * @param EntityType $other
75
     * @return bool
76
     */
77
    public function equals(EntityType $other)
78
    {
79
        return $this->type === $other->type;
80
    }
81
82
    public static function deserialize($data)
83
    {
84
        return new self($data);
85
    }
86
87
    public function serialize()
88
    {
89
        return $this->type;
90
    }
91
92
    public function __toString()
93
    {
94
        return $this->type;
95
    }
96
}
97