Completed
Push — master ( 1709bd...87026b )
by Łukasz
04:39 queued 02:13
created

HasDbDeployCheck::getLastErrorMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 4
loc 4
rs 10
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 View Code Duplication
class HasDbDeployCheck implements CheckInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
}