Total Complexity | 8 |
Total Lines | 66 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
5 | trait SleepTrait |
||
6 | { |
||
7 | /** @var int Time we need to wait between two request * */ |
||
8 | protected $sleep = 0; |
||
9 | |||
10 | /** |
||
11 | * Chainable `$waitBetweenRequests` setter. |
||
12 | * |
||
13 | * @return self |
||
14 | */ |
||
15 | public function setSleep($seconds) |
||
16 | { |
||
17 | $this->sleep = $seconds * 1000000; |
||
18 | |||
19 | return $this; |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * Return the time the script need to sleep. |
||
24 | * |
||
25 | * @return int Microseconds |
||
26 | */ |
||
27 | protected function getSleep() |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Exec sleep. |
||
38 | * |
||
39 | * @return int The time we rest |
||
40 | */ |
||
41 | public function execSleep() |
||
42 | { |
||
43 | if ($this->previousRequestUsedCache) { |
||
44 | return; |
||
45 | } |
||
46 | |||
47 | if ($this->sleep) { |
||
48 | $sleep = $this->getSleep(); |
||
49 | usleep($sleep); |
||
50 | |||
51 | return $sleep; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Exec a half sleep. |
||
57 | * |
||
58 | * @return int The time we rest |
||
59 | */ |
||
60 | public function execHalfSleep() |
||
71 | } |
||
72 | } |
||
74 |