Completed
Push — master ( b25810...38231d )
by Pavel
01:56
created

FileHandler   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 50%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A resolvePath() 0 8 2
A preparePath() 0 7 2
A getEnvParameter() 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 3
    public function __construct(array $arguments)
17
    {
18 3
        $this->arguments = $arguments;
19 3
    }
20
21
    public function resolvePath($currentPath, $importPath) {
22
        if (substr($importPath, 0, 1) == '/') {
23
            return $this->preparePath($importPath);
24
        } else {
25
            $path = dirname($currentPath) . DIRECTORY_SEPARATOR . $importPath;
26
            return $this->preparePath($path);
27
        }
28
    }
29
30 2
    public function preparePath($path) {
31 2
        if (($env = $this->getEnvParameter('env')) !== false) {
32 2
            return str_replace("{env}", $env, $path);
33
        } else {
34
            return $path;
35
        }
36
    }
37
38
    public function getEnvParameter($name) {
39 2
        return array_reduce($this->arguments, function($ret, $item) use ($name) {
40 2
            if (substr(strtolower($item), 0, 5) == '--' . $name) {
41 2
                $val = explode('=', $item);
42 2
                return trim($val[1]);
43
            }
44 2
        }, false);
45
46
    }
47
48
    public function initDirectory($dir) {
49
        if (!is_dir($dir)) {
50
            mkdir($dir);
51
        }
52
    }
53
}
54