Completed
Push — master ( 6eb58a...ff20ae )
by Jan-Petter
03:32
created

Delay::client()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace vipnytt\RobotsTxtParser;
3
4
use PDO;
5
use vipnytt\RobotsTxtParser\Client\Delay\ClientInterface;
6
use vipnytt\RobotsTxtParser\Client\Delay\ManagerInterface;
7
use vipnytt\RobotsTxtParser\Client\Directives\DelayInterface;
8
use vipnytt\RobotsTxtParser\Handler\DatabaseHandler;
9
use vipnytt\RobotsTxtParser\Parser\UriParser;
10
11
/**
12
 * Class Delay
13
 *
14
 * @see https://github.com/VIPnytt/RobotsTxtParser/blob/master/docs/methods/DelayManager.md for documentation
15
 * @package vipnytt\RobotsTxtParser
16
 */
17
final class Delay implements ManagerInterface
18
{
19
    use UriParser;
20
21
    /**
22
     * SQL Driver switch
23
     * @var DatabaseHandler
24
     */
25
    private $switch;
26
27
    /**
28
     * Handler
29
     * @var ManagerInterface
30
     */
31
    private $handler;
32
33
    /**
34
     * Delay constructor.
35
     *
36
     * @param PDO $pdo
37
     */
38
    public function __construct(PDO $pdo)
39
    {
40
        $this->switch = new DatabaseHandler($pdo);
41
        $this->handler = $this->switch->delayManager();
42
    }
43
44
    /**
45
     * Client
46
     *
47
     * @param DelayInterface $client
48
     * @return ClientInterface
49
     */
50
    public function client(DelayInterface $client)
51
    {
52
        return $this->switch->delayClient($client->getBaseUri(), $client->getUserAgent(), $client->getValue());
53
    }
54
55
    /**
56
     * Clean the delay table
57
     *
58
     * @param int $delay - in seconds
59
     * @return bool
60
     */
61
    public function clean($delay = 60)
62
    {
63
        return $this->handler->clean($delay);
64
    }
65
66
    /**
67
     * Top X wait time
68
     *
69
     * @param int $limit
70
     * @param int $min
71
     * @return array
72
     */
73
    public function getTopWaitTimes($limit = 100, $min = 0)
74
    {
75
        return $this->handler->getTopWaitTimes($limit, $min);
76
    }
77
}
78