| Conditions | 14 |
| Paths | 33 |
| Total Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 28 |
| CRAP Score | 14 |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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') { |
|
|
|
|||
| 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 |