Completed
Pull Request — master (#2)
by Jan-Petter
02:43
created

DelayMaintenanceSQL::clean()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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