Completed
Pull Request — develop (#232)
by Michiel
05:29 queued 02:47
created

UseRaaOption   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 50
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A getDefault() 0 4 1
A getUseRaaOption() 0 7 2
A equals() 0 4 1
A jsonSerialize() 0 4 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 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
class UseRaaOption implements JsonSerializable
25
{
26
    /**
27
     * @var string[]|null
28
     */
29
    private $useRaaOption;
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
        $this->useRaaOption = $useRaaOption;
45
    }
46
47
    public static function getDefault()
48
    {
49
        return new self(null);
50
    }
51
52
    /**
53
     * If array, returns the array sorted
54
     * @return null|string[]
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
55
     */
56
    public function getUseRaaOption()
57
    {
58
        if (is_array($this->useRaaOption)) {
59
            sort($this->useRaaOption);
60
        }
61
        return $this->useRaaOption;
62
    }
63
64
    public function equals(UseRaaOption $other)
65
    {
66
        return $this->getUseRaaOption() === $other->getUseRaaOption();
67
    }
68
69
    public function jsonSerialize()
70
    {
71
        return $this->getUseRaaOption();
72
    }
73
}
74