VisitTimeClient::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * vipnytt/RobotsTxtParser
4
 *
5
 * @link https://github.com/VIPnytt/RobotsTxtParser
6
 * @license https://github.com/VIPnytt/RobotsTxtParser/blob/master/LICENSE The MIT License (MIT)
7
 */
8
9
namespace vipnytt\RobotsTxtParser\Client\Directives;
10
11
/**
12
 * Class VisitTimeClient
13
 *
14
 * @see https://github.com/VIPnytt/RobotsTxtParser/blob/master/docs/methods/VisitTimeClient.md for documentation
15
 * @package vipnytt\RobotsTxtParser\Client\Directives
16
 */
17
class VisitTimeClient implements ClientInterface
18
{
19
    use DirectiveClientTrait;
20
21
    /**
22
     * Times
23
     * @var array
24
     */
25
    private $times = [];
26
27
    /**
28
     * RequestRateClient constructor.
29
     *
30
     * @param array $times
31
     */
32
    public function __construct(array $times)
33
    {
34
        $this->times = $times;
35
    }
36
37
    /**
38
     * Is visit-time
39
     *
40
     * @param int|null $timestamp
41
     * @return bool
42
     */
43
    public function isVisitTime($timestamp = null)
44
    {
45
        $timestamp = is_int($timestamp) ? $timestamp : time();
46
        foreach ($this->times as $time) {
47
            if ($this->isBetween($timestamp, $time['from'], $time['to'], 'Hi')) {
48
                return true;
49
            }
50
        }
51
        return empty($this->times);
52
    }
53
54
    /**
55
     * Export
56
     *
57
     * @return array
58
     */
59
    public function export()
60
    {
61
        return $this->times;
62
    }
63
}
64