| Conditions | 21 |
| Paths | 20 |
| Total Lines | 41 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 82 | private function extractKeyFromArgument(MethodCall $node, int $argIndex, string $classNamePart): void |
||
| 83 | { |
||
| 84 | $args = $node->args; |
||
| 85 | // find in funciton return array values |
||
| 86 | if (isset($args[$argIndex]) && $args[$argIndex]->value instanceof Closure && |
||
| 87 | isset($args[$argIndex]->value) && isset($args[$argIndex]->value) |
||
| 88 | ) { |
||
| 89 | $method = $node->name->name; |
||
| 90 | $closure = $args[$argIndex]->value; |
||
| 91 | if ($closure->stmts !== null) { |
||
| 92 | $return = reset($closure->stmts); |
||
| 93 | if ($return instanceof Return_ && $return->expr instanceof Array_ && $return->expr->items !== null) { |
||
| 94 | $items = $return->expr->items; |
||
| 95 | foreach ($items as $item) { |
||
| 96 | if ($item->value instanceof String_) { |
||
| 97 | $key = $item->value->value; |
||
| 98 | $this->addKey($item->value->getAttribute('startLine'), $method, $key, null); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | if (isset($args[$argIndex]) && $args[$argIndex]->value instanceof String_) { |
||
| 106 | $method = $node->name->name; |
||
| 107 | $arg = null; |
||
| 108 | if ($method === 'translate' && isset($args[$argIndex + 1]) && $args[$argIndex + 1]->value instanceof Node\Expr\Array_) { |
||
| 109 | $arg = $args[$argIndex + 1]->value->items[0]->key->value; |
||
| 110 | } |
||
| 111 | |||
| 112 | $key = $args[$argIndex]->value->value; |
||
| 113 | $allowEmptyTranslation = $this->config['ALLOW_EMPTY_TRANSLATION'] ?? []; |
||
| 114 | if ( |
||
| 115 | array_key_exists($classNamePart, $allowEmptyTranslation) && |
||
| 116 | array_key_exists($argIndex, $allowEmptyTranslation[$classNamePart]) && |
||
| 117 | ($key === '' || $key === '--') && |
||
| 118 | (in_array($method, $allowEmptyTranslation[$classNamePart][$argIndex], true)) |
||
| 119 | ) { |
||
| 120 | return; |
||
| 121 | } |
||
| 122 | $this->addKey($args[$argIndex]->getStartLine(), $method, $key, $arg); |
||
| 123 | } |
||
| 137 |