Completed
Push — master ( d401ab...1f0fb6 )
by Łukasz
02:47
created

HasDbDeployCheck   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 20%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 76
ccs 3
cts 15
cp 0.2
rs 10
c 1
b 1
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 7 1
A getErrorCode() 0 4 1
A getConnection() 0 4 1
A getLastErrorMessage() 0 4 1
A getSqlStatement() 0 4 1
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
     * @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
}
89