Conditions | 20 |
Paths | 20 |
Total Lines | 44 |
Code Lines | 39 |
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 |
||
45 | public static function factory($value) { |
||
46 | if (is_numeric($value)) { |
||
47 | return new Expressions\Number($value); |
||
48 | } elseif (preg_match('/^\$?[a-z]+$/', $value)) { |
||
49 | return new Expressions\Variable($value); |
||
50 | } |
||
51 | |||
52 | switch ($value) { |
||
53 | case '+': |
||
54 | return new Expressions\Addition($value); |
||
55 | case '-': |
||
56 | return new Expressions\Subtraction($value); |
||
57 | case '*': |
||
58 | return new Expressions\Multiplication($value); |
||
59 | case '/': |
||
60 | return new Expressions\Division($value); |
||
61 | case '%': |
||
62 | return new Expressions\Modulo($value); |
||
63 | case '?': |
||
64 | case ':': |
||
65 | return new Expressions\Ternary($value); |
||
66 | case '(': |
||
67 | case ')': |
||
68 | return new Expressions\Parenthesis($value); |
||
69 | case '==': |
||
70 | return new Expressions\ComparisonEQ($value); |
||
71 | case '<': |
||
72 | return new Expressions\ComparisonLT($value); |
||
73 | case '>': |
||
74 | return new Expressions\ComparisonGT($value); |
||
75 | case '<=': |
||
76 | return new Expressions\ComparisonLTE($value); |
||
77 | case '>=': |
||
78 | return new Expressions\ComparisonGTE($value); |
||
79 | case '!=': |
||
80 | return new Expressions\ComparisonNE($value); |
||
81 | case '||': |
||
82 | return new Expressions\OperatorOr($value); |
||
83 | case '&&': |
||
84 | return new Expressions\OperatorAnd($value); |
||
85 | } |
||
86 | |||
87 | throw new \RuntimeException('Undefined Value ' . $value); |
||
88 | } |
||
89 | |||
104 |