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