Meta::run()   C
last analyzed

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 4
    public function run(Filesystem $fs)
13
    {
14 4
        $routes = [];
15 4
        foreach ($fs->listClasses('Controller') as $class) {
16 4
            $nick = substr(strtolower($class), 11);
17 4
            $reflectionClass =new ReflectionClass($class);
18 4
            $traits = $reflectionClass->getTraits();
19 4
            $ignore = [];
20 4
            if (count($traits)) {
21 4
                foreach ($traits as $trait) {
22 4
                    foreach ($trait->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
23 4
                        if ($method->isConstructor() || $method->getName() == '__debugInfo') {
24 4
                            continue;
25
                        }
26 4
                        $ignore[] = $method->getName();
27
                    }
28
                }
29
            }
30 4
            $methods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC);
31 4
            foreach ($methods as $method) {
32 4
                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 4
                    continue;
34
                }
35 4
                if (in_array($method->name, $ignore)) {
36 4
                    continue;
37
                }
38 4
                if ($method->name == '__process') {
39 4
                    $routes[] = $nick.'/*';
40
                } else {
41 4
                    $routes[] = $nick.'/'.$method->name;
42
                }
43
            }
44
        }
45
46 4
        $jobs = [];
47 4
        foreach ($fs->listClasses('Job') as $class) {
48 4
            $reflection = new ReflectionClass($class);
49 4
            if (!$reflection->isAbstract()) {
50 4
                $jobs[] = str_replace('\\', '.', substr(strtolower($class), 4));
51
            }
52
        }
53
54 4
        return compact('routes', 'jobs');
55
    }
56
}
57