Completed
Push — master ( 456549...47da6e )
by Łukasz
02:25
created

HasDbDeployCheckInterface::getLastErrorMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Tworzenieweb\SqlProvisioner\Check;
4
5
use PDO;
6
use Tworzenieweb\SqlProvisioner\Database\Connection;
7
use Tworzenieweb\SqlProvisioner\Model\Candidate;
8
9
/**
10
 * @author Luke Adamczewski
11
 * @package Tworzenieweb\SqlProvisioner\Database
12
 */
13
class HasDbDeployCheckInterface implements CheckInterface
14
{
15
    const SQL = <<<SQL
16
SELECT `id`
17
FROM `%s`
18
WHERE `%s` = ?
19
SQL;
20
    const ERROR_STATUS = 'ALREADY_DEPLOYED';
21
22
    /** @var Connection */
23
    private $connection;
24
25
26
27
    /**
28
     * @param Connection $connection
29
     */
30
    public function __construct(Connection $connection)
31
    {
32
        $this->connection = $connection;
33
    }
34
35
36
37
    /**
38
     * @param Candidate $candidate
39
     * @return bool
40
     */
41
    public function execute(Candidate $candidate)
42
    {
43
        $statement = $this->getConnection()->prepare($this->getSqlStatement());
44
        $statement->execute([$candidate->getNumber()]);
45
46
        return (boolean) $statement->fetchColumn();
47
    }
48
49
50
51
    /**
52
     * @return string
53
     */
54
    public function getErrorCode()
55
    {
56
        return self::ERROR_STATUS;
57
    }
58
59
60
61
    /**
62
     * @return PDO
63
     */
64
    private function getConnection()
65
    {
66
        return $this->connection->getCurrentConnection();
67
    }
68
69
70
71
    /**
72
     * @return null
73
     */
74
    public function getLastErrorMessage()
75
    {
76
        return null;
77
    }
78
79
80
81
    /**
82
     * @return string
83
     */
84
    private function getSqlStatement()
85
    {
86
        return sprintf(self::SQL, $this->connection->getProvisioningTable(), $this->connection->getCriteriaColumn());
87
    }
88
}