Completed
Push — master ( e610ee...c79300 )
by Arne
04:09
created

UnlinkOperation::getRelativePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Storeman\Operation;
4
5
use Storeman\FileReader;
6
use Storeman\VaultLayout\VaultLayoutInterface;
7
8
class UnlinkOperation implements OperationInterface
9
{
10
    protected $relativePath;
11
12
    public function __construct(string $relativePath)
13
    {
14
        $this->relativePath = $relativePath;
15
    }
16
17
    public function getRelativePath(): string
18
    {
19
        return $this->relativePath;
20
    }
21
22
    public function execute(string $localBasePath, FileReader $fileReader, VaultLayoutInterface $vaultLayout): bool
23
    {
24
        $absolutePath = $localBasePath . $this->relativePath;
25
26
        if (is_file($absolutePath) || is_link($absolutePath))
27
        {
28
            return unlink($localBasePath . $this->relativePath);
29
        }
30
        elseif (is_dir($absolutePath))
31
        {
32
            return rmdir($absolutePath);
33
        }
34
35
        return false;
36
    }
37
38
    /**
39
     * @codeCoverageIgnore
40
     */
41
    public function __toString(): string
42
    {
43
        return "Unlink {$this->relativePath}";
44
    }
45
}
46