UnixFileMapping   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 77
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSource() 0 5 1
A __construct() 0 12 1
A getRelativeSource() 0 3 1
A getDestination() 0 5 1
A getRelativeDestination() 0 3 1
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