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

RaLocationId::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 RaLocationId implements JsonSerializable
26
{
27
    /**
28
     * @var string
29
     */
30
    private $raLocationId;
31
32
    /**
33
     * @param string $raLocationId
34
     */
35 View Code Duplication
    public function __construct($raLocationId)
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...
36
    {
37
        if (!is_string($raLocationId) || strlen(trim($raLocationId)) === 0) {
38
            throw InvalidArgumentException::invalidType(
39
                'non-empty string',
40
                'raLocationId',
41
                $raLocationId
42
            );
43
        }
44
45
        if (!Uuid::isValid($raLocationId)) {
46
            throw InvalidArgumentException::invalidType(
47
                'UUID',
48
                'raLocationId',
49
                $raLocationId
50
            );
51
        }
52
53
        $this->raLocationId = $raLocationId;
54
    }
55
56
    /**
57
     * @param RaLocationId $otherRaLocationId
58
     * @return bool
59
     */
60
    public function equals(RaLocationId $otherRaLocationId)
61
    {
62
        return $this->raLocationId === $otherRaLocationId->raLocationId;
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function getRaLocationId()
69
    {
70
        return $this->raLocationId;
71
    }
72
73
    public function __toString()
74
    {
75
        return $this->raLocationId;
76
    }
77
78
    public function jsonSerialize()
79
    {
80
        return $this->raLocationId;
81
    }
82
}
83