Completed
Push — feature/behat-support ( c4f7cb...a1a06f )
by Michiel
04:23
created

SelectRaaOption::equals()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 4
nop 1
1
<?php
2
3
/**
4
 * Copyright 2018 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not select 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 Surfnet\Stepup\Exception\InvalidArgumentException;
23
24 View Code Duplication
class SelectRaaOption implements JsonSerializable
0 ignored issues
show
Duplication introduced by
This class 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...
25
{
26
    /**
27
     * @var InstitutionSet|null
28
     */
29
    private $institutions;
30
31
    /**
32
     * SelectRaaOption constructor.
33
     * @param string[]|null $selectRaaOption
34
     */
35
    public function __construct($selectRaaOption)
36
    {
37
        if (!is_null($selectRaaOption) && !is_array($selectRaaOption)) {
38
            throw InvalidArgumentException::invalidType(
39
                'null or string[]',
40
                'selectRaaOption',
41
                $selectRaaOption
42
            );
43
        }
44
45
        // Sort the array values alphabetically
46
        if (is_array($selectRaaOption)) {
47
            sort($selectRaaOption);
48
            $this->institutions = InstitutionSet::fromInstitutionConfig($selectRaaOption);
49
        }
50
    }
51
52
    public static function getDefault()
53
    {
54
        return new self(null);
55
    }
56
57
    public function getInstitutions()
58
    {
59
        return $this->institutions;
60
    }
61
62
    public function equals(SelectRaaOption $other)
63
    {
64
        $thisValue = null;
65
        $otherValue = null;
66
        if (!is_null($this->getInstitutions())) {
67
            $thisValue = $this->getInstitutions()->toScalarArray();
68
        }
69
        if (!is_null($other->getInstitutions())) {
70
            $otherValue = $other->getInstitutions()->toScalarArray();
71
        }
72
        return $thisValue === $otherValue;
73
    }
74
75
    public function jsonSerialize()
76
    {
77
        return $this->getInstitutions()->toScalarArray();
78
    }
79
}
80