Test Failed
Pull Request — master (#448)
by
unknown
05:18
created

AbstractFileTask   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 59
ccs 0
cts 30
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getOptions() 0 14 3
getParameters() 0 1 ?
A getFile() 0 21 3
1
<?php
2
/*
3
 * This file is part of the Magallanes package.
4
 *
5
 * (c) Andrés Montañez <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Mage\Task\BuiltIn\FS;
12
13
use Mage\Task\Exception\ErrorException;
14
use Mage\Task\AbstractTask;
15
16
/**
17
 * File System Task - Abstract Base class for File Operations
18
 *
19
 * @author Andrés Montañez <[email protected]>
20
 */
21
abstract class AbstractFileTask extends AbstractTask
22
{
23
    /**
24
     * Returns the Task options
25
     *
26
     * @return array
27
     * @throws ErrorException
28
     */
29
    protected function getOptions()
30
    {
31
        $mandatory = $this->getParameters();
32
        $defaults = array_keys($this->getDefaults());
33
        $missing = array_diff($mandatory, $defaults);
34
35
        foreach ($missing as $parameter) {
36
            if (!array_key_exists($parameter, $this->options)) {
37
                throw new ErrorException(sprintf('Parameter "%s" is not defined', $parameter));
38
            }
39
        }
40
41
        return $this->options;
42
    }
43
44
    /**
45
     * Returns the mandatory parameters
46
     *
47
     * @return array
48
     */
49
    abstract protected function getParameters();
50
51
    /**
52
     * Returns a file with the placeholders replaced
53
     *
54
     * @param string $file
55
     * @return string
56
     * @throws ErrorException
57
     */
58
    protected function getFile($file)
59
    {
60
        $mapping = [
61
            '%environment%' => $this->runtime->getEnvironment(),
62
        ];
63
64
        if ($this->runtime->getHostName() !== null) {
65
            $mapping['%host%'] = $this->runtime->getHostName();
66
        }
67
68
        if ($this->runtime->getReleaseId() !== null) {
69
            $mapping['%release%'] = $this->runtime->getReleaseId();
70
        }
71
72
        $options = $this->getOptions();
73
        return str_replace(
74
            array_keys($mapping),
75
            array_values($mapping),
76
            $options[$file]
77
        );
78
    }
79
}
80