Completed
Pull Request — develop (#91)
by Boy
02:58
created

ServiceProvider::mayUseGateway()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Surfnet\StepupGateway\GatewayBundle\Entity;
4
5
use Surfnet\SamlBundle\Entity\ServiceProvider as BaseServiceProvider;
6
7
class ServiceProvider extends BaseServiceProvider
8
{
9
    /**
10
     * @return bool
11
     */
12
    public function mayUseGateway()
13
    {
14
        return !$this->mayUseSecondFactorOnly();
15
    }
16
17
    /**
18
     * @return bool
19
     */
20
    public function mayUseSecondFactorOnly()
21
    {
22
        return (bool) $this->get('secondFactorOnly', false);
23
    }
24
25
    /**
26
     * @param string $nameId
27
     * @return bool
28
     */
29
    public function isAllowedToUseSecondFactorOnlyFor($nameId)
30
    {
31
        if (empty($nameId)) {
32
            return false;
33
        }
34
35
        if (!$this->mayUseSecondFactorOnly()) {
36
            return false;
37
        }
38
39
        $nameIdPatterns = $this->get('secondFactorOnlyNameIdPatterns');
40
        foreach ($nameIdPatterns as $nameIdPattern) {
41
            if (fnmatch($nameIdPattern, $nameId)) {
42
                return true;
43
            }
44
        }
45
        return false;
46
    }
47
}
48