Completed
Push — master ( 1b6743...e69112 )
by Jan-Petter
9s
created

DelayClient::get()   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 0
1
<?php
2
namespace vipnytt\RobotsTxtParser\Client\Directives;
3
4
use PDO;
5
use vipnytt\RobotsTxtParser\Client\SQL\Delay\DelayHandlerSQL;
6
7
/**
8
 * Class DelayClient
9
 *
10
 * @package vipnytt\RobotsTxtParser\Client\Directives
11
 */
12
class DelayClient implements DelayInterface, ClientInterface
13
{
14
    /**
15
     * Base Uri
16
     * @var string
17
     */
18
    private $base;
19
20
    /**
21
     * User-agent
22
     * @var string
23
     */
24
    private $userAgent;
25
26
    /**
27
     * Value
28
     * @var float|int
29
     */
30
    private $value;
31
32
    /**
33
     * Export value
34
     * @var float|int
35
     */
36
    private $exportValue;
37
38
    /**
39
     * DelayClient constructor.
40
     *
41
     * @param string $baseUri
42
     * @param string $userAgent
43
     * @param float|int $value
44
     * @param float|int $fallbackValue
45
     */
46
    public function __construct($baseUri, $userAgent, $value, $fallbackValue = 0)
47
    {
48
        $this->base = $baseUri;
49
        $this->userAgent = $userAgent;
50
        $this->exportValue = $value;
51
        $this->value = $value > 0 ? $value : $fallbackValue;
52
    }
53
54
    /**
55
     * Get
56
     *
57
     * @return float|int
58
     */
59
    public function get()
60
    {
61
        return $this->value;
62
    }
63
64
    /**
65
     * Export
66
     *
67
     * @return float|int
68
     */
69
    public function export()
70
    {
71
        return $this->exportValue;
72
    }
73
74
    /**
75
     * SQL back-end
76
     *
77
     * @param PDO $pdo
78
     * @return DelayHandlerSQL
79
     */
80
    public function sql(PDO $pdo)
81
    {
82
        return new DelayHandlerSQL($pdo, $this->base, $this->userAgent, $this->value);
83
    }
84
}
85