Completed
Pull Request — develop (#172)
by A.
08:23 queued 03:53
created

AllowedSecondFactorList::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
/**
4
 * Copyright 2017 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 ArrayIterator;
22
use IteratorAggregate;
23
use JsonSerializable;
24
use Surfnet\StepupBundle\Value\SecondFactorType;
25
26
final class AllowedSecondFactorList implements JsonSerializable, IteratorAggregate
27
{
28
    /**
29
     * @var SecondFactorType[]
30
     */
31
    private $allowedSecondFactors;
32
33
    public function __construct(array $allowedSecondFactors)
34
    {
35
        foreach ($allowedSecondFactors as $allowedSecondFactor) {
36
            $this->initializeWith($allowedSecondFactor);
37
        }
38
    }
39
40
    /**
41
     * @param SecondFactorType $secondFactor
42
     * @return bool
43
     */
44
    public function isAllowed(SecondFactorType $secondFactor)
45
    {
46
        if (empty($this->allowedSecondFactors)) {
47
            return true;
48
        }
49
50
        foreach ($this->allowedSecondFactors as $allowedSecondFactor) {
51
            if ($allowedSecondFactor->equals($secondFactor)) {
0 ignored issues
show
Documentation introduced by
$secondFactor is of type object<Surfnet\StepupBun...Value\SecondFactorType>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52
                return true;
53
            }
54
        }
55
56
        return false;
57
    }
58
59
    public function getIterator()
60
    {
61
        return new ArrayIterator($this->allowedSecondFactors);
62
    }
63
64
    public function jsonSerialize()
65
    {
66
        return [
67
            'allowedSecondFactors' => $this->allowedSecondFactors
68
        ];
69
    }
70
71
    private function initializeWith(SecondFactorType $allowedSecondFactor)
72
    {
73
        $this->allowedSecondFactors[] = $allowedSecondFactor;
74
    }
75
}
76