HasDbDeployCheck::getErrorCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
cc 1
nc 1
nop 0
crap 2
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 HasDbDeployCheck 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 1
    public function __construct(Connection $connection)
31
    {
32 1
        $this->connection = $connection;
33 1
    }
34
35
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public function execute(Candidate $candidate): bool
41
    {
42
        $statement = $this->getConnection()->prepare($this->getSqlStatement());
43
        $statement->execute([$candidate->getNumber()]);
44
45
        return (boolean) $statement->fetchColumn();
46
    }
47
48
49
50
    /**
51
     * @inheritdoc
52
     */
53
    public function getErrorCode(): string
54
    {
55
        return self::ERROR_STATUS;
56
    }
57
58
59
60
    /**
61
     * @return PDO
62
     */
63
    private function getConnection()
64
    {
65
        return $this->connection->getCurrentConnection();
66
    }
67
68
69
70
    /**
71
     * @inheritdoc
72
     */
73
    public function getLastErrorMessage(): string
74
    {
75
        return '';
76
    }
77
78
79
80
    /**
81
     * @return string
82
     */
83
    private function getSqlStatement()
84
    {
85
        return sprintf(self::SQL, $this->connection->getProvisioningTable(), $this->connection->getCriteriaColumn());
86
    }
87
}
88