Total Complexity | 8 |
Total Lines | 36 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
12 | class LastTime |
||
13 | { |
||
14 | protected $filePath; |
||
15 | |||
16 | public function __construct(string $filePath) |
||
19 | } |
||
20 | |||
21 | public function wasRunSince(DateInterval $interval): bool |
||
22 | { |
||
23 | $previous = $this->get(); |
||
24 | |||
25 | if (false !== $previous |
||
26 | && $previous->add($interval) > new DateTime('now')) { |
||
27 | return false; |
||
28 | } |
||
29 | |||
30 | return true; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Return false if never runned else last datetime it was runned. |
||
35 | */ |
||
36 | public function get($default = false) |
||
37 | { |
||
38 | if (!file_exists($this->filePath)) { |
||
39 | return false === $default ? false : new DateTime($default); |
||
40 | } |
||
41 | |||
42 | return new DateTime(file_get_contents($this->filePath)); |
||
43 | } |
||
44 | |||
45 | public function set($datetime = 'now') |
||
48 | } |
||
49 | } |
||
50 |