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

RequireSecondFactorSelectedService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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