UnixFileMapping::getRelativeSource()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright Mediact. All rights reserved.
4
 * https://www.Mediact.nl
5
 */
6
7
namespace Mediact\FileMapping;
8
9
class UnixFileMapping implements FileMappingInterface
10
{
11
    /** @var string */
12
    private $sourceDirectory;
13
14
    /** @var string */
15
    private $destinationDirectory;
16
17
    /** @var string */
18
    private $source;
19
20
    /** @var string */
21
    private $destination;
22
23
    /**
24
     * Constructor.
25
     *
26
     * @param string $sourceDirectory
27
     * @param string $destinationDirectory
28
     * @param string $mapping
29
     */
30 3
    public function __construct(
31
        string $sourceDirectory,
32
        string $destinationDirectory,
33
        string $mapping
34
    ) {
35 3
        $this->sourceDirectory      = $sourceDirectory;
36 3
        $this->destinationDirectory = $destinationDirectory;
37
38
        // Expand the source and destination.
39 3
        static $pattern    = '/({(.*?),(.*?)})/';
40 3
        $this->source      = preg_replace($pattern, '$2', $mapping);
41 3
        $this->destination = preg_replace($pattern, '$3', $mapping);
42 3
    }
43
44
    /**
45
     * Get the relative path to the source file.
46
     *
47
     * @return string
48
     */
49 3
    public function getRelativeSource(): string
50
    {
51 3
        return $this->source;
52
    }
53
54
    /**
55
     * Get the absolute path to the source file.
56
     *
57
     * @return string
58
     */
59 1
    public function getSource(): string
60
    {
61 1
        return $this->sourceDirectory
62 1
            . DIRECTORY_SEPARATOR
63 1
            . $this->source;
64
    }
65
66
    /**
67
     * Get the relative path to the destination file.
68
     *
69
     * @return string
70
     */
71 3
    public function getRelativeDestination(): string
72
    {
73 3
        return $this->destination;
74
    }
75
76
    /**
77
     * Get the absolute path to the destination file.
78
     *
79
     * @return string
80
     */
81 1
    public function getDestination(): string
82
    {
83 1
        return $this->destinationDirectory
84 1
            . DIRECTORY_SEPARATOR
85 1
            . $this->destination;
86
    }
87
}
88