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

RequireSecondFactorSelectedService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A requireSelectedSecondFactor() 0 14 2
1
<?php
2
3
4
namespace Surfnet\StepupGateway\GatewayBundle\Service;
5
6
use Psr\Log\LoggerInterface;
7
use Surfnet\StepupGateway\GatewayBundle\Saml\ResponseContext;
8
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
9
10
class RequireSecondFactorSelectedService
11
{
12
    /**
13
     * @var ResponseContext
14
     */
15
    private $responseContext;
16
17
    /**
18
     * RequireSecondFactorSelectedService constructor.
19
     * @param ResponseContext $responseContext
20
     */
21
    public function __construct(ResponseContext $responseContext)
22
    {
23
        $this->responseContext = $responseContext;
24
    }
25
26
    /**
27
     * @param LoggerInterface $contextualLogger
28
     * @return string
29
     */
30
    public function requireSelectedSecondFactor(LoggerInterface $contextualLogger)
31
    {
32
        $selectedSecondFactor = $this->responseContext->getSelectedSecondFactor();
33
34
        if (!$selectedSecondFactor) {
35
            $contextualLogger->error(
36
              'Cannot verify possession of an unknown second factor'
37
            );
38
39
            throw new BadRequestHttpException('Cannot verify possession of an unknown second factor.');
40
        }
41
42
        return $selectedSecondFactor;
43
    }
44
}
45