| Conditions | 9 |
| Paths | 1 |
| Total Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 81 | public static function create( |
||
| 82 | array $options = [], |
||
| 83 | ...$args |
||
| 84 | ): self { |
||
| 85 | |||
| 86 | $pagerUriManager = (function (array $args) use ($options): PagerUriManagerInterface { |
||
| 87 | foreach ($args as $arg) { |
||
| 88 | if ($arg instanceof PagerUriManagerInterface) { |
||
| 89 | return $arg; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | return new PagerUriManager($options[PagerComponent::getName() . '_uri'] ?? []); |
||
| 94 | })($args); |
||
| 95 | |||
| 96 | $sortUriManager = (function (array $args) use ($options, $pagerUriManager): SortUriManagerInterface { |
||
| 97 | foreach ($args as $arg) { |
||
| 98 | if ($arg instanceof SortUriManagerInterface) { |
||
| 99 | return $arg; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | return new SortUriManager($options[SortComponent::getName() . '_uri'] ?? [], $pagerUriManager); |
||
| 104 | })($args); |
||
| 105 | |||
| 106 | $filterUriManager = (function (array $args) use ($options, $pagerUriManager): FilterUriManagerInterface { |
||
| 107 | foreach ($args as $arg) { |
||
| 108 | if ($arg instanceof FilterUriManagerInterface) { |
||
| 109 | return $arg; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | return new FilterUriManager($options[FilterComponent::getName() . '_uri'] ?? [], $pagerUriManager); |
||
| 114 | })($args); |
||
| 115 | |||
| 116 | $breakDownUriManager = (function (array $args) use ($options, $pagerUriManager, $sortUriManager): BreakDownUriManagerInterface { |
||
| 117 | foreach ($args as $arg) { |
||
| 118 | if ($arg instanceof BreakDownUriManagerInterface) { |
||
| 119 | return $arg; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | return new BreakDownUriManager($options[BreakDownComponent::getName() . '_uri'] ?? [], $pagerUriManager, $sortUriManager); |
||
| 124 | })($args); |
||
| 125 | |||
| 126 | return new self([ |
||
| 127 | new PagerComponentFactory($options[PagerComponent::getName()] ?? [], $pagerUriManager), |
||
| 128 | new SortComponentFactory($options[SortComponent::getName()] ?? [], $sortUriManager), |
||
| 129 | new FilterComponentFactory($options[FilterComponent::getName()] ?? [], $filterUriManager), |
||
| 130 | new BreakDownComponentFactory($options[BreakDownComponent::getName()] ?? [], $breakDownUriManager), |
||
| 131 | ]); |
||
| 132 | } |
||
| 133 | } |
||
| 134 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.