| Conditions | 10 | 
| Paths | 7 | 
| Total Lines | 37 | 
| Code Lines | 24 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 0 | 
| CRAP Score | 110 | 
| Changes | 2 | ||
| 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 | ||
| 19 | protected function compile($expr, Context $context) | ||
| 20 |     { | ||
| 21 | $compiler = $context->getExpressionCompiler(); | ||
| 22 | $var = $compiler->compile($expr->var); | ||
| 23 | $dim = $compiler->compile($expr->dim); | ||
|  | |||
| 24 | |||
| 25 | if ($var->getType() === CompiledExpression::UNIMPLEMENTED | ||
| 26 | || $dim->getType() === CompiledExpression::UNIMPLEMENTED | ||
| 27 |         ) { | ||
| 28 | return new CompiledExpression(CompiledExpression::UNIMPLEMENTED); | ||
| 29 | } | ||
| 30 | |||
| 31 | if (!$var->isTypeKnown() || !$dim->isTypeKnown() | ||
| 32 | || !$var->isCorrectValue() || !$dim->isCorrectValue() | ||
| 33 |         ) { | ||
| 34 | return new CompiledExpression(); | ||
| 35 | } | ||
| 36 | |||
| 37 |         switch ($var->getType()) { | ||
| 38 | case CompiledExpression::STRING: | ||
| 39 | case CompiledExpression::ARR: | ||
| 40 |                 if ($dim->isArray()) { | ||
| 41 | $context->notice( | ||
| 42 | 'language_error', | ||
| 43 | 'Illegal offset type', | ||
| 44 | $expr | ||
| 45 | ); | ||
| 46 | return new CompiledExpression(); | ||
| 47 | } | ||
| 48 | break; | ||
| 49 | default: | ||
| 50 | break; | ||
| 51 | } | ||
| 52 | |||
| 53 | $resultArray = $var->getValue(); | ||
| 54 | return CompiledExpression::fromZvalValue($resultArray[$dim->getValue()]); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | 
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: