Completed
Push — master ( 5be531...114bf3 )
by Łukasz
03:06
created

Executor::getConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Tworzenieweb\SqlProvisioner\Database;
4
5
use PDO;
6
use PDOException;
7
use Tworzenieweb\SqlProvisioner\Model\Candidate;
8
9
/**
10
 * @author Luke Adamczewski
11
 * @package Tworzenieweb\SqlProvisioner\Database
12
 */
13
class Executor
14
{
15
    /** @var Connection */
16
    private $connection;
17
18
19
20
    /**
21
     * @param Connection $connection
22
     */
23 2
    public function __construct(Connection $connection)
24
    {
25 2
        $this->connection = $connection;
26 2
    }
27
28
29
30
    /**
31
     * @param Candidate $candidate
32
     * @throws Exception
33
     */
34 2
    public function execute(Candidate $candidate)
35
    {
36 2
        $connection = $this->getConnection();
37
38
        try {
39 2
            $statement = $connection->prepare($candidate->getContent());
40 2
            $statement->execute();
41 2
        } catch (PDOException $pdoException) {
42 1
            throw Exception::candidateScriptError($candidate, $pdoException);
43
        }
44 1
    }
45
46
47
48
    /**
49
     * @return PDO
50
     */
51 2
    private function getConnection()
52
    {
53 2
        return $this->connection->getCurrentConnection();
54
    }
55
}
56