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