| Conditions | 11 |
| Paths | 130 |
| Total Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 11.0207 |
| 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 | 4 | public function applyToNode(Node $node) |
|
| 22 | { |
||
| 23 | 4 | $instruction = $node->getInstruction($this); |
|
| 24 | |||
| 25 | 4 | if (is_array($instruction) || is_object($instruction)) { |
|
| 26 | 4 | $instruction = (object)$instruction; |
|
| 27 | } |
||
| 28 | |||
| 29 | 4 | if (!isset($instruction) || !isset($instruction->input)) { |
|
| 30 | return; |
||
| 31 | } |
||
| 32 | |||
| 33 | 4 | $locale = isset($instruction->locale) ? $instruction->locale : 'en_US'; |
|
| 34 | 4 | $decimals = isset($instruction->decimals) ? $instruction->decimals : null; |
|
| 35 | 4 | $currency = isset($instruction->currency) ? $instruction->currency : null; |
|
| 36 | 4 | $style = $currency ? NumberFormatter::CURRENCY : NumberFormatter::DECIMAL; |
|
| 37 | |||
| 38 | 4 | $number = new NumberFormatter($locale, $style); |
|
| 39 | |||
| 40 | 4 | if (isset($decimals)) { |
|
| 41 | 1 | $number->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimals); |
|
| 42 | } |
||
| 43 | |||
| 44 | 4 | $result = $currency ? |
|
| 45 | 1 | $number->formatCurrency($instruction->input, $currency) : |
|
| 46 | 4 | $number->format($instruction->input); |
|
| 47 | |||
| 48 | 4 | $node->setResult($result); |
|
| 49 | 4 | } |
|
| 50 | } |
||
| 51 |