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