Conditions | 15 |
Paths | 15 |
Total Lines | 33 |
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 |
||
51 | function toPHP() { |
||
52 | if(!$this->param2) return $this->param1->toPHP(); |
||
53 | $p1 = $this->param1->toPHP(); |
||
54 | $p2 = $this->param2->toPHP(); |
||
55 | switch($this->operator) { |
||
56 | case "equals": |
||
57 | case "equal": |
||
58 | return $p1." == ".$p2; |
||
59 | case "notequals": |
||
60 | case "notequal": |
||
61 | return $p1." != ".$p2; |
||
62 | case "less": |
||
63 | return $p1." < ".$p2; |
||
64 | case "greater": |
||
65 | return $p1." > ".$p2; |
||
66 | case "has": |
||
67 | return "in_array($p2, $p1)"; |
||
68 | case "starts": |
||
69 | return "strpos($p1, $p2) === 0"; |
||
70 | case "contains": |
||
71 | return "strpos($p1, $p2) !== FALSE"; |
||
72 | case "ends": |
||
73 | return "substr($p1, -strlen($p2)) === $p2"; |
||
74 | case "or": |
||
75 | case "and": |
||
76 | case "xor": |
||
77 | throw new Exception\Unimplemented("OR/AND/XOR Unimplmented at this time"); |
||
78 | // return "($p1) OR ($p2)"; |
||
79 | // return "($p1) AND ($p2)"; |
||
80 | // return "($p1) XOR ($p2)"; |
||
81 | } |
||
82 | return ""; |
||
83 | } |
||
84 | function toHTML($escape = false) { |
||
87 | } |