Completed
Push — develop ( dae12f...f18ec7 )
by Daan van
02:40
created

EntityType::equals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace OpenConext\Value\Saml;
4
5
use OpenConext\Value\Exception\InvalidArgumentException;
6
7
final class EntityType
8
{
9
    const TYPE_SP  = 'saml20-sp';
10
    const TYPE_IDP = 'saml20-idp';
11
12
    /**
13
     * @var string
14
     */
15
    private $type;
16
17
    /**
18
     * @param string $type
19
     */
20
    public function __construct($type)
21
    {
22
        if (!in_array($type, array(self::TYPE_SP, self::TYPE_IDP))) {
23
            throw new InvalidArgumentException('EntityType must be one of EntityType::TYPE_SP or EntityType::TYPE_IDP');
24
        }
25
26
        $this->type = $type;
27
    }
28
29
    /**
30
     * Creates a new ServiceProvider Type
31
     * @return EntityType
32
     *
33
     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
34
     * @SuppressWarnings(PHPMD.ShortMethodName)
35
     */
36
    public static function SP()
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
37
    {
38
        return new EntityType(self::TYPE_SP);
39
    }
40
41
    // @codingStandardsIgnoreStart
42
    /**
43
     * Creates a new IdentityProvider Type
44
     * @return EntityType
45
     *
46
     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
47
     */
48
    public static function IdP()
49
    {
50
        return new EntityType(self::TYPE_IDP);
51
    }
52
    // @codingStandardsIgnoreEnd
53
54
    /**
55
     * @return bool
56
     */
57
    public function isServiceProvider()
58
    {
59
        return $this->type === self::TYPE_SP;
60
    }
61
62
    /**
63
     * @return bool
64
     */
65
    public function isIdentityProvider()
66
    {
67
        return $this->type === self::TYPE_IDP;
68
    }
69
70
    /**
71
     * @param EntityType $other
72
     * @return bool
73
     */
74
    public function equals(EntityType $other)
75
    {
76
        return $this->type === $other->type;
77
    }
78
79
    public function __toString()
80
    {
81
        return $this->type;
82
    }
83
}
84