Test Failed
Push — master ( aaab1b...c0baad )
by
unknown
57s
created

UnixFileMapping   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 77
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
    public function __construct(
31
        string $sourceDirectory,
32
        string $destinationDirectory,
33
        string $mapping
34
    ) {
35
        $this->sourceDirectory      = $sourceDirectory;
36
        $this->destinationDirectory = $destinationDirectory;
37
38
        // Expand the source and destination.
39
        static $pattern    = '/({(.*),(.*)})/';
40
        $this->source      = preg_replace($pattern, '$2', $mapping);
41
        $this->destination = preg_replace($pattern, '$3', $mapping);
42
    }
43
44
    /**
45
     * Get the relative path to the source file.
46
     *
47
     * @return string
48
     */
49
    public function getRelativeSource(): string
50
    {
51
        return $this->source;
52
    }
53
54
    /**
55
     * Get the absolute path to the source file.
56
     *
57
     * @return string
58
     */
59
    public function getSource(): string
60
    {
61
        return $this->sourceDirectory
62
            . DIRECTORY_SEPARATOR
63
            . $this->source;
64
    }
65
66
    /**
67
     * Get the relative path to the destination file.
68
     *
69
     * @return string
70
     */
71
    public function getRelativeDestination(): string
72
    {
73
        return $this->destination;
74
    }
75
76
    /**
77
     * Get the absolute path to the destination file.
78
     *
79
     * @return string
80
     */
81
    public function getDestination(): string
82
    {
83
        return $this->destinationDirectory
84
            . DIRECTORY_SEPARATOR
85
            . $this->destination;
86
    }
87
}
88