Code Duplication    Length = 63-64 lines in 2 locations

src/Surfnet/Stepup/Configuration/Value/UseRaOption.php 1 location

@@ 24-87 (lines=64) @@
21
use JsonSerializable;
22
use Surfnet\Stepup\Exception\InvalidArgumentException;
23
24
class UseRaOption implements JsonSerializable
25
{
26
    /**
27
     * @var InstitutionSet|null
28
     */
29
    private $institutions;
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
        // Sort the array values alphabetically
46
        if (is_array($useRaOption)) {
47
            sort($useRaOption);
48
            $this->institutions = InstitutionSet::fromInstitutionConfig($useRaOption);
49
        }
50
    }
51
52
    public static function getDefault()
53
    {
54
        return new self(null);
55
    }
56
57
    public function equals(UseRaOption $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 isOption($option){
71
        return is_array($this->institutions) && in_array($this->institutions, $option);
72
    }
73
74
    public function hasOptions(){
75
        return is_array($this->institutions);
76
    }
77
78
    public function getInstitutions()
79
    {
80
        return $this->institutions;
81
    }
82
83
    public function jsonSerialize()
84
    {
85
        return $this->getInstitutions()->toScalarArray();
86
    }
87
}
88

src/Surfnet/Stepup/Configuration/Value/UseRaaOption.php 1 location

@@ 24-86 (lines=63) @@
21
use JsonSerializable;
22
use Surfnet\Stepup\Exception\InvalidArgumentException;
23
24
class UseRaaOption implements JsonSerializable
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 isOption($option){
71
        return is_array($this->institutions) && in_array($this->institutions, $option);
72
    }
73
74
    public function hasOptions(){
75
        return is_array($this->institutions);
76
    }
77
78
    public function getInstitutions()
79
    {
80
        return $this->institutions;
81
    }
82
    public function jsonSerialize()
83
    {
84
        return $this->getInstitutions()->toScalarArray();
85
    }
86
}
87