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

UseRaOption   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A getDefault() 0 4 1
A equals() 0 4 1
A getUseRaOption() 0 7 2
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 UseRaOption implements JsonSerializable
25
{
26
    /**
27
     * @var string[]|null
28
     */
29
    private $useRaOption;
30
31
    /**
32
     * UseRaOption constructor.
33
     * @param null|array $useRaOption
34
     */
35
    public function __construct($useRaOption)
36
    {
37
        if (!is_null($useRaOption) && !is_array($useRaOption)) {
38
            throw InvalidArgumentException::invalidType(
39
                'null or string[]',
40
                'useRaOption',
41
                $useRaOption
42
            );
43
44
        }
45
        $this->useRaOption = $useRaOption;
46
    }
47
48
    public static function getDefault()
49
    {
50
        return new self(null);
51
    }
52
53
    public function equals(UseRaOption $other)
54
    {
55
        return $this->getUseRaOption() === $other->getUseRaOption();
56
    }
57
58
    /**
59
     * If array, returns the array sorted
60
     * @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...
61
     */
62
    public function getUseRaOption()
63
    {
64
        if (is_array($this->useRaOption)) {
65
            sort($this->useRaOption);
66
        }
67
        return $this->useRaOption;
68
    }
69
70
    public function jsonSerialize()
71
    {
72
        return $this->getUseRaOption();
73
    }
74
}
75