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

FileHandler   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 95.45%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 49
ccs 21
cts 22
cp 0.9545
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A preparePath() 0 7 2
A resolvePath() 0 8 2
A getArgumentValue() 0 9 2
A initDirectory() 0 5 2
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