Completed
Branch 2.0-dev (d250b8)
by Jan-Petter
03:02
created

DelayMaintenanceSQL   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 14.58 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 7
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A clean() 0 9 1
A setup() 7 7 2

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
namespace vipnytt\RobotsTxtParser\Client\SQL\Delay;
3
4
use PDO;
5
use vipnytt\RobotsTxtParser\Client\SQL\SQLInterface;
6
use vipnytt\RobotsTxtParser\Client\SQL\SQLTrait;
7
use vipnytt\RobotsTxtParser\Exceptions\SQLException;
8
9
/**
10
 * Class DelayMaintenanceSQL
11
 *
12
 * @package vipnytt\RobotsTxtParser\Client\SQL\Delay
13
 */
14
class DelayMaintenanceSQL implements SQLInterface
15
{
16
    use SQLTrait;
17
18
    /**
19
     * @var PDO
20
     */
21
    private $pdo;
22
23
    /**
24
     * Maintenance constructor.
25
     *
26
     * @param PDO $pdo
27
     */
28
    public function __construct(PDO $pdo)
29
    {
30
        $this->pdo = $this->pdoInitialize($pdo);
31
    }
32
33
    /**
34
     * Clean the delay table
35
     *
36
     * @return bool
37
     */
38
    public function clean()
39
    {
40
        $query = $this->pdo->prepare(<<<SQL
41
DELETE FROM robotstxt__delay0
42
WHERE microTime < (UNIX_TIMESTAMP() * 1000000);
43
SQL
44
        );
45
        return $query->execute();
46
    }
47
48
    /**
49
     * Create SQL table
50
     *
51
     * @return bool
52
     * @throws SQLException
53
     */
54 View Code Duplication
    public function setup()
0 ignored issues
show
Duplication introduced by
This method 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...
55
    {
56
        if (!$this->createTable($this->pdo, self::TABLE_DELAY, file_get_contents(__DIR__ . '/delay.sql'))) {
57
            throw new SQLException('Unable to create table! Please read instructions at ' . self::README_SQL_DELAY);
58
        }
59
        return true;
60
    }
61
}
62