Completed
Push — feature/warn-on-non-utc-usage ( f71ca6...75a7ba )
by Boy
12:02 queued 07:38
created

InstitutionConfigurationId::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 20
Code Lines 12

Duplication

Lines 20
Ratio 100 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 20
loc 20
rs 9.2
cc 4
eloc 12
nc 3
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 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 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...
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