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

HasDbDeployCheck   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 6
c 1
b 1
f 0
lcom 1
cbo 2
dl 76
loc 76
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A execute() 7 7 1
A getErrorCode() 4 4 1
A getConnection() 4 4 1
A getLastErrorMessage() 4 4 1
A getSqlStatement() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}