Completed
Push — master ( f08c31...be488a )
by Dmitry
03:45
created

Meta::run()   C

Complexity

Conditions 14
Paths 33

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 14

Importance

Changes 0
Metric Value
dl 0
loc 44
ccs 28
cts 28
cp 1
rs 6.2666
c 0
b 0
f 0
cc 14
nc 33
nop 1
crap 14

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Basis\Job\Module;
4
5
use Basis\Filesystem;
6
use Basis\Job;
7
use ReflectionClass;
8
use ReflectionMethod;
9
10
class Meta extends Job
11
{
12 7
    public function run(Filesystem $fs)
13
    {
14 7
        $routes = [];
15 7
        foreach ($fs->listClasses('Controller') as $class) {
16 7
            $nick = substr(strtolower($class), 11);
17 7
            $reflectionClass =new ReflectionClass($class);
18 7
            $traits = $reflectionClass->getTraits();
19 7
            $ignore = [];
20 7
            if (count($traits)) {
21 7
                foreach ($traits as $trait) {
22 7
                    foreach ($trait->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
23 7
                        if ($method->isConstructor() || $method->getName() == '__debugInfo') {
24 7
                            continue;
25
                        }
26 7
                        $ignore[] = $method->getName();
27
                    }
28
                }
29
            }
30 7
            $methods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC);
31 7
            foreach ($methods as $method) {
32 7
                if ($method->isConstructor() || $method->getName() == '__debugInfo') {
0 ignored issues
show
Bug introduced by
Consider using $method->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
33 7
                    continue;
34
                }
35 7
                if (in_array($method->name, $ignore)) {
36 7
                    continue;
37
                }
38 7
                if ($method->name == '__process') {
39 7
                    $routes[] = $nick.'/*';
40
                } else {
41 7
                    $routes[] = $nick.'/'.$method->name;
42
                }
43
            }
44
        }
45
46 7
        $jobs = [];
47 7
        foreach ($fs->listClasses('Job') as $class) {
48 7
            $reflection = new ReflectionClass($class);
49 7
            if (!$reflection->isAbstract()) {
50 7
                $jobs[] = str_replace('\\', '.', substr(strtolower($class), 4));
51
            }
52
        }
53
54 7
        return compact('routes', 'jobs');
55
    }
56
}
57