Completed
Push — master ( 011ecd...5f8cc7 )
by Pavel
01:58
created

FileHandler::preparePath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2.0625
1
<?php
2
3
namespace Paro\BuildParametersHandler;
4
5
class FileHandler
6
{
7
    /**
8
     * @var array
9
     */
10
    private $arguments;
11
12
    /**
13
     * FileHandler constructor.
14
     * @param array $arguments
15
     */
16 10
    public function __construct(array $arguments)
17
    {
18 10
        $this->arguments = $arguments;
19 10
    }
20
21 4
    public function resolvePath($currentPath, $importPath) {
22 4
        if (substr($importPath, 0, 1) == DIRECTORY_SEPARATOR) {
23 1
            return $this->preparePath($importPath);
24
        } else {
25 3
            $path = dirname($currentPath) . DIRECTORY_SEPARATOR . $importPath;
26 3
            return $this->preparePath($path);
27
        }
28
    }
29
30 7
    public function preparePath($path) {
31 7
        if (($env = $this->getArgumentValue('env')) !== false) {
32 7
            return str_replace("{env}", $env, $path);
33
        } else {
34
            return $path;
35
        }
36
    }
37
38
    public function getArgumentValue($name) {
39 9
        return array_reduce($this->arguments, function($ret, $item) use ($name) {
40 9
            if (substr(strtolower($item), 0, strlen($name)+2) == '--' . $name) {
41 8
                $val = explode('=', $item);
42 8
                return trim($val[1]);
43
            }
44 9
        }, false);
45
46
    }
47
48 1
    public function initDirectory($dir) {
49 1
        if (!is_dir($dir)) {
50 1
            mkdir($dir);
51 1
        }
52 1
    }
53
}
54