Completed
Push — feature/ra-location-projection... ( 904ccf...4cd14e )
by A.
04:43 queued 11s
created

InstitutionConfigurationId::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
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 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
     * @param Institution $institution
33
     * @return InstitutionConfigurationId
34
     */
35
    public static function from(Institution $institution)
36
    {
37
        return new self((string) Uuid::uuid5(self::UUID_NAMESPACE, $institution->getInstitution()));
38
    }
39
40 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...
41
    {
42
        if (!is_string($institutionConfigurationId) || strlen(trim($institutionConfigurationId)) === 0) {
43
            throw InvalidArgumentException::invalidType(
44
                'non-empty string',
45
                'institutionConfigurationId',
46
                $institutionConfigurationId
47
            );
48
        }
49
50
        if (!Uuid::isValid($institutionConfigurationId)) {
51
            throw InvalidArgumentException::invalidType(
52
                'UUID',
53
                'institutionConfigurationId',
54
                $institutionConfigurationId
55
            );
56
        }
57
58
        $this->institutionConfigurationId = $institutionConfigurationId;
59
    }
60
61
    /**
62
     * @param InstitutionConfigurationId $otherInstitutionConfigurationId
63
     * @return bool
64
     */
65
    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...
66
    {
67
        return $this->institutionConfigurationId === $otherInstitutionConfigurationId->institutionConfigurationId;
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getInstitutionConfigurationId()
74
    {
75
        return $this->institutionConfigurationId;
76
    }
77
78
    public function __toString()
79
    {
80
        return $this->institutionConfigurationId;
81
    }
82
83
    public function jsonSerialize()
84
    {
85
        return $this->institutionConfigurationId;
86
    }
87
}
88