Completed
Push — master ( 42afef...5f18df )
by Dmitry
06:49 queued 03:50
created

Filesystem   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 98.28%

Importance

Changes 5
Bugs 0 Features 4
Metric Value
wmc 21
c 5
b 0
f 4
lcom 1
cbo 1
dl 0
loc 92
ccs 57
cts 58
cp 0.9828
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A exists() 0 5 2
A getPath() 0 15 4
B listClasses() 0 24 4
C listFiles() 0 23 7
A completeClassName() 0 8 3
1
<?php
2
3
namespace Basis;
4
5
class Filesystem
6
{
7
    private $app;
8
    protected $root;
9
10 10
    function __construct(Application $app, $root)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
11
    {
12 10
        $this->app = $app;
13 10
        $this->root = $root;
14 10
    }
15
16 8
    function exists()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
17
    {
18 8
        $path = call_user_func_array([$this, 'getPath'], func_get_args());
19 8
        return is_dir($path) || file_exists($path);
20
    }
21
22 8
    function getPath()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
23
    {
24 8
        if (func_get_args()) {
25 8
            $chain = func_get_args();
26 8
            array_unshift($chain, $this->root);
27 8
            foreach ($chain as $k => $v) {
28 8
                if (!strlen($v)) {
29 1
                    unset($chain[$k]);
30 1
                }
31 8
            }
32 8
            return implode(DIRECTORY_SEPARATOR, array_values($chain));
33
        }
34
35 8
        return $this->root;
36
    }
37
38 1
    function listClasses($namespace = '')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
39
    {
40 1
        $location = "src/php";
41
42 1
        if($namespace) {
43 1
            $location .= '/'.str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
44 1
        }
45
46 1
        $files = $this->listFiles($location);
47 1
        $classes = [];
48
49 1
        $namespace = $this->completeClassName($namespace);
50
51 1
        foreach($files as $file) {
52 1
            $class = str_replace(['\\', '/'], '\\', $file);
53 1
            $class = substr($class, 0, -4);
54 1
            if($namespace) {
55 1
                $class = $namespace.'\\'.$class;
56 1
            }
57 1
            $classes[] = $class;
58 1
        }
59
60 1
        return $classes;
61
    }
62
63 7
    function listFiles($location)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
64
    {
65 7
        $absolute = $this->getPath($location);
66 7
        if (!is_dir($absolute)) {
67
            return [];
68
        }
69
70 7
        $result = [];
71 7
        $relative = substr($absolute, strlen($this->getPath()));
72 7
        foreach (scandir($absolute) as $file) {
73 7
            if ($file != '.' && $file != '..') {
74 7
                if (is_file("$absolute/$file")) {
75 7
                    $result[] = $file;
76 7
                } else {
77 2
                    foreach ($this->listFiles("$relative/$file") as $child) {
78 2
                        $result[] = "$file/$child";
79 2
                    }
80
                }
81 7
            }
82 7
        }
83
84 7
        return $result;
85
    }
86
87 5
    function completeClassName($namespace)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
88
    {
89 5
        $config = $this->app->get(Config::class);
90 5
        if($config['app.namespace']) {
91 5
            $namespace = $config['app.namespace'].($namespace ? '\\'.$namespace:'');
92 5
        }
93 5
        return $namespace;
94
    }
95
96
}
97