GssfService   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 40
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A startVerification() 0 4 1
A verify() 0 14 3
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupRa\RaBundle\Service;
20
21
use Surfnet\StepupRa\RaBundle\Service\Gssf\VerificationResult;
22
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
23
24
final class GssfService
25
{
26
    /**
27
     * @var \Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface
28
     */
29
    private $state;
30
31
    public function __construct(AttributeBagInterface $state)
32
    {
33
        $this->state = $state;
34
    }
35
36
    /**
37
     * @param string $gssfId
38
     * @param string $procedureId
39
     */
40
    public function startVerification($gssfId, $procedureId)
41
    {
42
        $this->state->set('current_verification', ['procedureId' => $procedureId, 'gssfId' => $gssfId]);
43
    }
44
45
    /**
46
     * @param string $gssfId
47
     * @return VerificationResult
48
     */
49
    public function verify($gssfId)
50
    {
51
        $verification = $this->state->remove('current_verification');
52
53
        if (!$verification) {
54
            return VerificationResult::noSuchProcedure();
55
        }
56
57
        if ($gssfId === $verification['gssfId']) {
58
            return VerificationResult::verificationSucceeded($verification['procedureId']);
59
        }
60
61
        return VerificationResult::verificationFailed($verification['procedureId']);
62
    }
63
}
64