Completed
Pull Request — develop (#167)
by A.
09:49 queued 04:39
created

InstitutionConfigurationId::normalizedFrom()   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 1
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 JsonSerializable;
22
use Rhumsaa\Uuid\Uuid;
23
use Surfnet\Stepup\Exception\InvalidArgumentException;
24
25
final class InstitutionConfigurationId implements JsonSerializable
26
{
27
    const UUID_NAMESPACE = '09876543-abcd-0987-abcd-098765432109';
28
29
    private $institutionConfigurationId;
30
31
    /**
32
     * @deprecated To be removed in next release; use normalizedFrom method to account for case-(in)sensitivity issues
33
     *
34
     * @param Institution $institution
35
     * @return InstitutionConfigurationId
36
     */
37
    public static function from(Institution $institution)
38
    {
39
        return new self((string) Uuid::uuid5(self::UUID_NAMESPACE, $institution->getInstitution()));
40
    }
41
42
    /**
43
     * @param Institution $institution
44
     * @return InstitutionConfigurationId
45
     */
46
    public static function normalizedFrom(Institution $institution)
47
    {
48
        return new self((string) Uuid::uuid5(self::UUID_NAMESPACE, strtolower($institution->getInstitution())));
49
    }
50
51 View Code Duplication
    public function __construct($institutionConfigurationId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
    {
53
        if (!is_string($institutionConfigurationId) || strlen(trim($institutionConfigurationId)) === 0) {
54
            throw InvalidArgumentException::invalidType(
55
                'non-empty string',
56
                'institutionConfigurationId',
57
                $institutionConfigurationId
58
            );
59
        }
60
61
        if (!Uuid::isValid($institutionConfigurationId)) {
62
            throw InvalidArgumentException::invalidType(
63
                'UUID',
64
                'institutionConfigurationId',
65
                $institutionConfigurationId
66
            );
67
        }
68
69
        $this->institutionConfigurationId = $institutionConfigurationId;
70
    }
71
72
    /**
73
     * @param InstitutionConfigurationId $otherInstitutionConfigurationId
74
     * @return bool
75
     */
76
    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...
77
    {
78
        return $this->institutionConfigurationId === $otherInstitutionConfigurationId->institutionConfigurationId;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getInstitutionConfigurationId()
85
    {
86
        return $this->institutionConfigurationId;
87
    }
88
89
    public function __toString()
90
    {
91
        return $this->institutionConfigurationId;
92
    }
93
94
    public function jsonSerialize()
95
    {
96
        return $this->institutionConfigurationId;
97
    }
98
}
99