| Conditions | 10 |
| Paths | 10 |
| Total Lines | 33 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 22 |
| CRAP Score | 10.0082 |
| 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 |
||
| 21 | 43 | protected function compile($expr, Context $context) |
|
| 22 | { |
||
| 23 | 43 | $compiler = $context->getExpressionCompiler(); |
|
| 24 | |||
| 25 | 43 | if ($expr->items === []) { |
|
| 26 | 29 | return new CompiledExpression(CompiledExpression::ARR, []); |
|
| 27 | } |
||
| 28 | |||
| 29 | 16 | $resultArray = []; |
|
| 30 | |||
| 31 | 16 | foreach ($expr->items as $item) { |
|
| 32 | 16 | if ($item === null) { |
|
| 33 | continue; |
||
| 34 | } |
||
| 35 | |||
| 36 | 16 | $compiledValueResult = $compiler->compile($item->value); |
|
| 37 | 16 | if ($item->key) { |
|
| 38 | 6 | $compiledKeyResult = $compiler->compile($item->key); |
|
| 39 | 6 | switch ($compiledKeyResult->getType()) { |
|
| 40 | 6 | case CompiledExpression::INTEGER: |
|
| 41 | 6 | case CompiledExpression::DOUBLE: |
|
| 42 | 6 | case CompiledExpression::BOOLEAN: |
|
| 43 | 6 | case CompiledExpression::NULL: |
|
| 44 | 6 | case CompiledExpression::STRING: |
|
| 45 | 6 | $resultArray[$compiledKeyResult->getValue()] = $compiledValueResult->getValue(); |
|
| 46 | 6 | } |
|
| 47 | 6 | } else { |
|
| 48 | 10 | $resultArray[] = $compiledValueResult->getValue(); |
|
| 49 | } |
||
| 50 | 16 | } |
|
| 51 | |||
| 52 | 16 | return new CompiledExpression(CompiledExpression::ARR, $resultArray); |
|
| 53 | } |
||
| 54 | } |
||
| 55 |