Completed
Push — feature/ra-locations-model ( 2f2725...94c409 )
by A.
05:16
created

InstitutionConfigurationId::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * Copyright 2016 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\Stepup\Configuration\Value;
20
21
use Rhumsaa\Uuid\Uuid;
22
use Surfnet\Stepup\Exception\InvalidArgumentException;
23
24
final class InstitutionConfigurationId
25
{
26
    const UUID_NAMESPACE = '09876543-abcd-0987-abcd-098765432109';
27
28
    private $institutionConfigurationId;
29
30
    /**
31
     * @param Institution $institution
32
     * @return InstitutionConfigurationId
33
     */
34
    public static function from(Institution $institution)
35
    {
36
        return new self((string) Uuid::uuid5(self::UUID_NAMESPACE, $institution->getInstitution()));
37
    }
38
39
    public function __construct($institutionConfigurationId)
40
    {
41
        if (!is_string($institutionConfigurationId) || strlen(trim($institutionConfigurationId)) === 0) {
42
            throw InvalidArgumentException::invalidType(
43
                'non-empty string',
44
                'institutionConfigurationId',
45
                $institutionConfigurationId
46
            );
47
        }
48
49
        if (!Uuid::isValid($institutionConfigurationId)) {
50
            throw InvalidArgumentException::invalidType(
51
                'UUID',
52
                'institutionConfigurationId',
53
                $institutionConfigurationId
54
            );
55
        }
56
57
        $this->institutionConfigurationId = $institutionConfigurationId;
58
    }
59
60
    /**
61
     * @param InstitutionConfigurationId $otherInstitutionConfigurationId
62
     * @return bool
63
     */
64
    public function equals(InstitutionConfigurationId $otherInstitutionConfigurationId)
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $otherInstitutionConfigurationId exceeds the maximum configured length of 30.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
65
    {
66
        return $this->institutionConfigurationId === $otherInstitutionConfigurationId->institutionConfigurationId;
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function getInstitutionConfigurationId()
73
    {
74
        return $this->institutionConfigurationId;
75
    }
76
77
    public function __toString()
78
    {
79
        return $this->institutionConfigurationId;
80
    }
81
}
82