SymlinkOperation::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Storeman\Operation;
4
5
use Storeman\FileReader;
6
use Storeman\VaultLayout\VaultLayoutInterface;
7
8
class SymlinkOperation implements OperationInterface
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $relativePath;
14
15
    /**
16
     * @var string
17
     */
18
    protected $relativeLinkTarget;
19
20
    public function __construct(string $relativePath, string $relativeLinkTarget)
21
    {
22
        $this->relativePath = $relativePath;
23
        $this->relativeLinkTarget = $relativeLinkTarget;
24
    }
25
26
    public function execute(string $localBasePath, FileReader $fileReader, VaultLayoutInterface $vaultLayout): bool
27
    {
28
        $absolutePath = $localBasePath . $this->relativePath;
29
        $absoluteLinkTarget = $localBasePath . $this->relativeLinkTarget;
30
31
        return symlink($absoluteLinkTarget, $absolutePath);
32
    }
33
34
    /**
35
     * @codeCoverageIgnore
36
     */
37
    public function __toString(): string
38
    {
39
        return sprintf('Symlink %s to %s', $this->relativePath, $this->relativeLinkTarget);
40
    }
41
}
42