Conditions | 11 |
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 |
||
20 | public function run(ModelsCommand $command, Model $model): void |
||
21 | { |
||
22 | $traits = class_uses_recursive($model); |
||
23 | |||
24 | if (!in_array(HasJsonRelationships::class, $traits)) { |
||
25 | return; // @codeCoverageIgnore |
||
26 | } |
||
27 | |||
28 | $methods = (new ReflectionClass($model))->getMethods(ReflectionMethod::IS_PUBLIC); |
||
29 | |||
30 | foreach ($methods as $method) { |
||
31 | if ($method->isAbstract() || $method->isStatic() || !$method->isPublic() |
||
32 | || $method->getNumberOfParameters() > 0 || $method->getDeclaringClass()->getName() === Model::class) { |
||
33 | continue; |
||
34 | } |
||
35 | |||
36 | try { |
||
37 | $relationship = $method->invoke($model); |
||
38 | } catch (Throwable) { // @codeCoverageIgnore |
||
39 | continue; // @codeCoverageIgnore |
||
40 | } |
||
41 | |||
42 | if ($relationship instanceof BelongsToJson || $relationship instanceof HasManyJson) { |
||
43 | $this->addRelationship($command, $method, $relationship); |
||
44 | } |
||
69 |