| Conditions | 18 |
| Paths | 173 |
| Total Lines | 56 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 95 | private function resolveStmt(array $expressions, string $parentId, bool $leaveNodes = false): void |
||
| 96 | { |
||
| 97 | foreach ($expressions as &$expression) { |
||
| 98 | if ($expression instanceof Expression || $expression instanceof Return_) { |
||
| 99 | $expression = $expression->expr; |
||
| 100 | $fromStmt = true; // $expression is from stmt |
||
| 101 | |||
| 102 | if ($expression instanceof Expr\Assign) { |
||
| 103 | $expression = &$expression->expr; |
||
| 104 | } |
||
| 105 | } elseif (\property_exists($expression, 'value') && $expression->value instanceof \PhpParser\Node) { |
||
| 106 | $expression = &$expression->value; |
||
| 107 | } |
||
| 108 | |||
| 109 | if (\property_exists($expression, 'expr')) { |
||
| 110 | $this->doReplacement($expression, $parentId, $leaveNodes, $expR); |
||
| 111 | |||
| 112 | if ($expression instanceof Expr\Variable || $expR) { |
||
| 113 | continue; |
||
| 114 | } |
||
| 115 | |||
| 116 | $expression = &$expression->expr; |
||
| 117 | } |
||
| 118 | |||
| 119 | if ($expression instanceof Expr\MethodCall) { |
||
| 120 | $exprVar = &$expression->var; |
||
| 121 | |||
| 122 | if (!$expression instanceof Expr\Variable) { |
||
| 123 | $this->doReplacement($exprVar, $parentId, $leaveNodes); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | if ($expression instanceof Expr\CallLike) { |
||
| 128 | $this->resolveStmt($expression->args, $parentId, $leaveNodes); |
||
| 129 | |||
| 130 | if (isset($fromStmt)) { |
||
| 131 | continue; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | if ($expression instanceof Expr\Array_) { |
||
| 136 | if (isset($this->replacement[$parentId][\spl_object_id($expression)]) && $leaveNodes) { |
||
| 137 | $removeIds = \array_intersect_key( |
||
| 138 | \array_keys($this->replacement[$parentId]), |
||
| 139 | \array_map(fn (Expr\ArrayItem $i) => \spl_object_id($i->value), $expression->items) |
||
| 140 | ); |
||
| 141 | |||
| 142 | foreach ($removeIds as $removeId) { |
||
| 143 | unset($this->replacement[$parentId][$removeId]); |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | $this->resolveStmt($expression->items, $parentId, $leaveNodes); |
||
| 148 | } |
||
| 149 | |||
| 150 | $this->doReplacement($expression, $parentId, $leaveNodes); |
||
| 151 | } |
||
| 174 |