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

WhitelistRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Surfnet\StepupGateway\Behat\Repository;
4
5
use Exception;
6
7
/**
8
 * A poor mans repository, a pdo connection to the test database is established in the constructor
9
 */
10
class WhitelistRepository
11
{
12
    /**
13
     * @var Connection
14
     */
15
    private $connection;
16
17
    public function __construct(Connection $connection)
18
    {
19
        $this->connection = $connection;
20
    }
21
22
    /**
23
     * @param string $institution
24
     * @return array
25
     * @throws Exception
26
     */
27
    public function whitelist($institution)
28
    {
29
        $sql = "INSERT INTO whitelist_entry (`institution`) VALUES (:institution);";
30
        $stmt = $this->connection->prepare($sql);
31
        $data = ['institution' => $institution];
32
        if ($stmt->execute($data)) {
33
            return $data;
34
        }
35
36
        throw new Exception('Unable add the institution to the whitelist');
37
    }
38
}
39