Conditions | 10 |
Paths | 18 |
Total Lines | 43 |
Lines | 9 |
Ratio | 20.93 % |
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 |
||
69 | function renderStTag() { |
||
70 | $out = "<" . "?php "; |
||
71 | $scopeName = ""; |
||
72 | if (preg_match('/ as ([a-zA-Z]+)$/', $this->var, $m)) { |
||
73 | $scopeName = $m[1]; |
||
74 | $lookup = substr($this->var, 0, strlen($this->var) - strlen($m[0])); |
||
75 | $hsv = new H\Text(trim($lookup), H\Text::TOKEN_CONTROL); |
||
76 | } else |
||
77 | $hsv = new H\Text($this->var, H\Text::TOKEN_CONTROL); |
||
78 | switch ($this->type) { |
||
79 | case "each": |
||
80 | if ($this->var) |
||
81 | $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n"; |
||
82 | else |
||
83 | $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n"; |
||
84 | $out .= "Hamle\\Scope::add({$this->o}); "; |
||
85 | break; |
||
86 | case "if": |
||
87 | $hsvcomp = new H\Text\Comparison($this->var); |
||
88 | $out .= "if(" . $hsvcomp->toPHP() . ") {"; |
||
89 | break; |
||
90 | case "with": |
||
91 | if ($scopeName) |
||
92 | $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;"; |
||
93 | else { |
||
94 | $out .= "if(({$this->o} = " . $hsv->toPHP() . ") && " . |
||
95 | "{$this->o}->valid()) {\n"; |
||
96 | $out .= "Hamle\\Scope::add({$this->o});\n;"; |
||
97 | } |
||
98 | break; |
||
99 | case "else": |
||
100 | $out .= "/* else */"; |
||
101 | break; |
||
102 | case "include": |
||
103 | $file = $hsv->toHTML(); |
||
104 | if($file[0] == "#") |
||
105 | $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
||
106 | else |
||
107 | $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
||
108 | break; |
||
109 | } |
||
110 | return $out . ' ?>'; |
||
111 | } |
||
112 | |||
150 | } |