Completed
Pull Request — feature/test-php-7-2-in-travis (#309)
by
unknown
04:53 queued 02:32
created

SecondFactorProvePossessionHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 * Copyright 2010 SURFnet B.V.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
namespace Surfnet\Stepup\Helper;
19
20
use Surfnet\StepupBundle\Service\SecondFactorTypeService;
21
use Surfnet\StepupBundle\Value\SecondFactorType;
22
use Webmozart\Assert\Assert;
23
24
class SecondFactorProvePossessionHelper
25
{
26
    /**
27
     * @var array
28
     */
29
    private $skipProvePossessionSecondFactorTypes;
30
31
    /**
32
     * @param SecondFactorTypeService $secondFactorTypeService
33
     * @param array $skipProvePossessionSecondFactorTypes
34
     */
35
    public function __construct(
36
        SecondFactorTypeService $secondFactorTypeService,
37
        array $skipProvePossessionSecondFactorTypes
38
    ) {
39
        Assert::allInArray(
40
            $skipProvePossessionSecondFactorTypes,
41
            $secondFactorTypeService->getAvailableSecondFactorTypes(),
42
            'Unsupported second factor type configured to skip prove possession'
0 ignored issues
show
Unused Code introduced by
The call to Assert::allInArray() has too many arguments starting with 'Unsupported second fact... skip prove possession'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
43
        );
44
45
        $this->skipProvePossessionSecondFactorTypes = $skipProvePossessionSecondFactorTypes;
46
    }
47
48
    /**
49
     * @param SecondFactorType $secondFactorType
50
     * @return bool
51
     */
52
    public function canSkipProvePossession(SecondFactorType $secondFactorType)
53
    {
54
        if (in_array($secondFactorType->getSecondFactorType(), $this->skipProvePossessionSecondFactorTypes)) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return in_array($secondF...sionSecondFactorTypes);.
Loading history...
55
            return true;
56
        }
57
58
        return false;
59
    }
60
}
61