Completed
Push — master ( 1b6642...22d6fd )
by Tomas
29s queued 10s
created

SharedFileRestart::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Tomaj\Hermes\Restart;
5
6
use DateTime;
7
8
class SharedFileRestart implements RestartInterface
9
{
10
    private $filePath;
11 9
12
    public function __construct(string $filePath)
13 9
    {
14 9
        $this->filePath = $filePath;
15
    }
16
17
    /**
18
     * {@inheritdoc}
19 9
     */
20
    public function shouldRestart(DateTime $startTime): bool
21 9
    {
22 3
        if (!file_exists($this->filePath)) {
23
            return false;
24
        }
25 6
26 6
        $time = filemtime($this->filePath);
27 3
        if ($time >= $startTime->getTimestamp()) {
28
            return true;
29
        }
30 3
31
        return false;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     *
37
     * Creates file defined in contructor with modification time `$restartTime` (or current DateTime).
38
     */
39 View Code Duplication
    public function restart(DateTime $restartTime = null): bool
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        if ($restartTime === null) {
42
            $restartTime = new DateTime();
43
        }
44
45
        return touch($this->filePath, (int) $restartTime->format('U'));
46
    }
47
}
48