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

UseRaaOption::getInstitutions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 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 Surfnet\Stepup\Exception\InvalidArgumentException;
23
24 View Code Duplication
class UseRaaOption 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
     * UseRaaOption constructor.
33
     * @param string[]|null $useRaaOption
34
     */
35
    public function __construct($useRaaOption)
36
    {
37
        if (!is_null($useRaaOption) && !is_array($useRaaOption)) {
38
            throw InvalidArgumentException::invalidType(
39
                'null or string[]',
40
                'useRaaOption',
41
                $useRaaOption
42
            );
43
        }
44
45
        // Sort the array values alphabetically
46
        if (is_array($useRaaOption)) {
47
            sort($useRaaOption);
48
            $this->institutions = InstitutionSet::fromInstitutionConfig($useRaaOption);
49
        }
50
    }
51
52
    public static function getDefault()
53
    {
54
        return new self(null);
55
    }
56
57
    public function equals(UseRaaOption $other)
58
    {
59
        $thisValue = null;
60
        $otherValue = null;
61
        if (!is_null($this->getInstitutions())) {
62
            $thisValue = $this->getInstitutions()->toScalarArray();
63
        }
64
        if (!is_null($other->getInstitutions())) {
65
            $otherValue = $other->getInstitutions()->toScalarArray();
66
        }
67
        return $thisValue === $otherValue;
68
    }
69
70
    public function getInstitutions()
71
    {
72
        return $this->institutions;
73
    }
74
75
    public function jsonSerialize()
76
    {
77
        return $this->getInstitutions()->toScalarArray();
78
    }
79
}
80