Conditions | 13 |
Paths | 12 |
Total Lines | 44 |
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 |
||
140 | public function getScript() |
||
141 | { |
||
142 | $sJsCode = ''; |
||
143 | switch($this->sType) |
||
144 | { |
||
145 | case Jaxon::FORM_VALUES: |
||
146 | $sJsCode = $this->getJsCall('getFormValues', $this->xValue); |
||
147 | break; |
||
148 | case Jaxon::INPUT_VALUE: |
||
149 | $sJsCode = $this->getJsCall('$', $this->xValue) . '.value'; |
||
150 | break; |
||
151 | case Jaxon::CHECKED_VALUE: |
||
152 | $sJsCode = $this->getJsCall('$', $this->xValue) . '.checked'; |
||
153 | break; |
||
154 | case Jaxon::ELEMENT_INNERHTML: |
||
155 | $sJsCode = $this->getJsCall('$', $this->xValue) . '.innerHTML'; |
||
156 | break; |
||
157 | case Jaxon::QUOTED_VALUE: |
||
158 | $sJsCode = $this->getQuotedValue(addslashes($this->xValue)); |
||
159 | break; |
||
160 | case Jaxon::BOOL_VALUE: |
||
161 | $sJsCode = ($this->xValue) ? 'true' : 'false'; |
||
162 | break; |
||
163 | case Jaxon::PAGE_NUMBER: |
||
164 | $sJsCode = (string)$this->xValue; |
||
165 | break; |
||
166 | case Jaxon::NUMERIC_VALUE: |
||
167 | $sJsCode = (string)$this->xValue; |
||
168 | break; |
||
169 | case Jaxon::JS_VALUE: |
||
170 | if(is_array($this->xValue) || is_object($this->xValue)) |
||
171 | { |
||
172 | // Unable to use double quotes here because they cannot be handled on client side. |
||
173 | // So we are using simple quotes even if the Json standard recommends double quotes. |
||
174 | $sJsCode = str_replace(['"'], ["'"], json_encode($this->xValue, JSON_HEX_APOS | JSON_HEX_QUOT)); |
||
175 | } |
||
176 | else |
||
177 | { |
||
178 | $sJsCode = (string)$this->xValue; |
||
179 | } |
||
180 | break; |
||
181 | } |
||
182 | return $sJsCode; |
||
183 | } |
||
184 | |||
207 |