Completed
Pull Request — feature/acceptance-tests (#191)
by Michiel
02:42 queued 58s
created

SecondFactorRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 42 2
1
<?php
2
3
namespace Surfnet\StepupGateway\Behat\Repository;
4
5
use Exception;
6
use Ramsey\Uuid\Uuid;
7
8
/**
9
 * A poor mans repository, a pdo connection to the test database is established in the constructor
10
 */
11
class SecondFactorRepository
12
{
13
    /**
14
     * @var Connection
15
     */
16
    private $connection;
17
18
    public function __construct(Connection $connection)
19
    {
20
        $this->connection = $connection;
21
    }
22
23
    public function create($nameId, $tokenType, $institution)
24
    {
25
        $uuid = Uuid::uuid4()->toString();
26
        $data = [
27
            'identityId' => $uuid,
28
            'nameId' => $nameId,
29
            'institution' => $institution,
30
            'secondFactorId' => $uuid,
31
            'secondFactorType' => $tokenType,
32
            'secondFactorIdentifier' => $uuid,
33
            'id' => $uuid,
34
            'displayLocale' => 'en_GB',
35
        ];
36
        $sql = <<<SQL
37
            INSERT INTO second_factor (
38
                identity_id, 
39
                name_id, 
40
                institution, 
41
                second_factor_id, 
42
                second_factor_type, 
43
                second_factor_identifier, 
44
                id, 
45
                display_locale
46
            )
47
            VALUES (
48
                :identityId, 
49
                :nameId, 
50
                :institution, 
51
                :secondFactorId, 
52
                :secondFactorType, 
53
                :secondFactorIdentifier, 
54
                :id, 
55
                :displayLocale
56
            )
57
SQL;
58
        $stmt = $this->connection->prepare($sql);
59
        if ($stmt->execute($data)) {
60
            return $data;
61
        }
62
63
        throw new Exception('Unable to insert the new second_factor');
64
    }
65
}
66