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

ServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 7
c 2
b 0
f 2
lcom 1
cbo 1
dl 0
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A mayUseGateway() 0 4 1
A mayUseSecondFactorOnly() 0 4 1
B isAllowedToUseSecondFactorOnlyFor() 0 18 5
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