Conditions | 13 |
Paths | 12 |
Total Lines | 45 |
Lines | 12 |
Ratio | 26.67 % |
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 |
||
114 | public function getScript() |
||
115 | { |
||
116 | $sJsCode = ''; |
||
117 | $sQuoteCharacter = "'"; |
||
118 | switch($this->sType) |
||
119 | { |
||
120 | View Code Duplication | case Jaxon::FORM_VALUES: |
|
|
|||
121 | $sJsCode = "jaxon.getFormValues(" . $sQuoteCharacter . $this->xValue . $sQuoteCharacter . ")"; |
||
122 | break; |
||
123 | View Code Duplication | case Jaxon::INPUT_VALUE: |
|
124 | $sJsCode = "jaxon.$(" . $sQuoteCharacter . $this->xValue . $sQuoteCharacter . ").value"; |
||
125 | break; |
||
126 | View Code Duplication | case Jaxon::CHECKED_VALUE: |
|
127 | $sJsCode = "jaxon.$(" . $sQuoteCharacter . $this->xValue . $sQuoteCharacter . ").checked"; |
||
128 | break; |
||
129 | View Code Duplication | case Jaxon::ELEMENT_INNERHTML: |
|
130 | $sJsCode = "jaxon.$(" . $sQuoteCharacter . $this->xValue . $sQuoteCharacter . ").innerHTML"; |
||
131 | break; |
||
132 | case Jaxon::QUOTED_VALUE: |
||
133 | $sJsCode = $sQuoteCharacter . addslashes($this->xValue) . $sQuoteCharacter; |
||
134 | break; |
||
135 | case Jaxon::BOOL_VALUE: |
||
136 | $sJsCode = ($this->xValue) ? 'true' : 'false'; |
||
137 | break; |
||
138 | case Jaxon::PAGE_NUMBER: |
||
139 | $sJsCode = (string)$this->xValue; |
||
140 | break; |
||
141 | case Jaxon::NUMERIC_VALUE: |
||
142 | $sJsCode = (string)$this->xValue; |
||
143 | break; |
||
144 | case Jaxon::JS_VALUE: |
||
145 | if(is_array($this->xValue) || is_object($this->xValue)) |
||
146 | { |
||
147 | // Unable to use double quotes here because they cannot be handled on client side. |
||
148 | // So we are using simple quotes even if the Json standard recommends double quotes. |
||
149 | $sJsCode = str_replace(['"'], ["'"], json_encode($this->xValue, JSON_HEX_APOS | JSON_HEX_QUOT)); |
||
150 | } |
||
151 | else |
||
152 | { |
||
153 | $sJsCode = (string)$this->xValue; |
||
154 | } |
||
155 | break; |
||
156 | } |
||
157 | return $sJsCode; |
||
158 | } |
||
159 | |||
182 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.