Connection   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 24
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A prepare() 0 3 1
1
<?php
2
3
/**
4
 * Copyright 2020 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\StepupGateway\Behat\Repository;
20
21
use PDO;
22
use PDOStatement;
23
24
class Connection
25
{
26
    /**
27
     * @var PDO
28
     */
29
    private $connection;
30
31
    public function __construct(string $appEnv, $dbUser, $dbPassword, $dbName, $hostName)
32
    {
33
        if ($appEnv !== 'smoketest') {
34
            die('Behat tests should only run in smoketest');
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
35
        }
36
37
        $dsn = 'mysql:host=%s;dbname=%s';
38
        // Open a PDO connection
39
        $this->connection = new PDO(sprintf($dsn, $hostName, $dbName), $dbUser, $dbPassword);
40
    }
41
42
    /**
43
     * @return bool|PDOStatement
44
     */
45
    public function prepare($statement)
46
    {
47
        return $this->connection->prepare($statement);
48
    }
49
}
50