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' |
|
|
|
|
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)) { |
|
|
|
|
55
|
|
|
return true; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return false; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
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.