Conditions | 10 |
Paths | 6 |
Total Lines | 24 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 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 |
||
19 | public function run(ModelsCommand $command, Model $model): void |
||
20 | { |
||
21 | $traits = class_uses_recursive($model); |
||
22 | |||
23 | if (!in_array(HasMergedRelationships::class, $traits)) { |
||
24 | return; // @codeCoverageIgnore |
||
25 | } |
||
26 | |||
27 | $methods = (new ReflectionClass($model))->getMethods(ReflectionMethod::IS_PUBLIC); |
||
28 | |||
29 | foreach ($methods as $method) { |
||
30 | if ($method->isAbstract() || $method->isStatic() || !$method->isPublic() |
||
31 | || $method->getNumberOfParameters() > 0 || $method->getDeclaringClass()->getName() === Model::class) { |
||
32 | continue; |
||
33 | } |
||
34 | |||
35 | try { |
||
36 | $relationship = $method->invoke($model); |
||
37 | } catch (Throwable) { // @codeCoverageIgnore |
||
38 | continue; // @codeCoverageIgnore |
||
39 | } |
||
40 | |||
41 | if ($relationship instanceof MergedRelation) { |
||
42 | $this->addRelationship($command, $method, $relationship); |
||
43 | } |
||
68 |