TouchOperation   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 48
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getRelativePath() 0 4 1
A getMtime() 0 4 1
A execute() 0 9 1
A __toString() 0 6 1
1
<?php
2
3
namespace Storeman\Operation;
4
5
use Storeman\FileReader;
6
use Storeman\FilesystemUtility;
7
use Storeman\VaultLayout\VaultLayoutInterface;
8
9
class TouchOperation implements OperationInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $relativePath;
15
16
    /**
17
     * @var float
18
     */
19
    protected $mtime;
20
21
    public function __construct(string $relativePath, float $mtime)
22
    {
23
        $this->relativePath = $relativePath;
24
        $this->mtime = $mtime;
25
    }
26
27
    public function getRelativePath(): string
28
    {
29
        return $this->relativePath;
30
    }
31
32
    public function getMtime(): float
33
    {
34
        return $this->mtime;
35
    }
36
37
    public function execute(string $localBasePath, FileReader $fileReader, VaultLayoutInterface $vaultLayout): bool
38
    {
39
        $absolutePath = $localBasePath . $this->relativePath;
40
        $time = FilesystemUtility::buildTime($this->mtime);
41
42
        exec("touch -m -d '{$time}' {$absolutePath} 2>&1", $output, $exitCode);
43
44
        return $exitCode === 0;
45
    }
46
47
    /**
48
     * @codeCoverageIgnore
49
     */
50
    public function __toString(): string
51
    {
52
        $timeString = FilesystemUtility::buildTime($this->mtime);
53
54
        return "Touch '{$this->relativePath}' to mtime = {$timeString}";
55
    }
56
}
57