| Conditions | 9 |
| Paths | 40 |
| Total Lines | 70 |
| 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 |
||
| 153 | public function editView($fields = array()) |
||
| 154 | { |
||
| 155 | $config = ConfigProvider::getInstance(); |
||
| 156 | $sessionProvider = $config->get('session.provider.name'); |
||
| 157 | $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); |
||
| 158 | |||
| 159 | $html = '<table cols="2" class="edit_view" style="width:100%; margin:0px">'; |
||
| 160 | $html .= '<form action="'.$fields['formAction'].'" method="POST" accept-charset="UTF-8">'; |
||
| 161 | |||
| 162 | $textBox = new TextBox($this->record->getPropObject('content'), $this->record->getDataLabel('content'), 'content', '', 5, $this->record->getID()); |
||
| 163 | $html .= $textBox->render(); |
||
| 164 | |||
| 165 | $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('version_num')) : 'version_num'); |
||
| 166 | $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->record->getVersion().'"/>'; |
||
| 167 | $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordID')) : 'ActiveRecordID'); |
||
| 168 | $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->record->getID().'"/>'; |
||
| 169 | |||
| 170 | // render special buttons for admins only |
||
| 171 | if ($session->get('currentUser')->inGroup('Admin') && strpos($fields['formAction'], '/tk/') !== false) { |
||
| 172 | $html .= '<tr><td colspan="2">'; |
||
| 173 | |||
| 174 | $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('saveBut')) : 'saveBut'); |
||
| 175 | $temp = new Button('submit', 'Save', $fieldname); |
||
| 176 | $html .= $temp->render(); |
||
| 177 | $html .= ' '; |
||
| 178 | $js = "$('#dialogDiv').text('Are you sure you wish to delete this item?'); |
||
| 179 | $('#dialogDiv').dialog({ |
||
| 180 | buttons: { |
||
| 181 | 'OK': function(event, ui) { |
||
| 182 | $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordID')) : 'ActiveRecordID')."\"]').attr('value', '".$this->record->getID()."'); |
||
| 183 | $('#deleteForm').submit(); |
||
| 184 | }, |
||
| 185 | 'Cancel': function(event, ui) { |
||
| 186 | $(this).dialog('close'); |
||
| 187 | } |
||
| 188 | } |
||
| 189 | }) |
||
| 190 | $('#dialogDiv').dialog('open'); |
||
| 191 | return false;"; |
||
| 192 | $temp = new Button($js, 'Delete', 'deleteBut'); |
||
| 193 | $html .= $temp->render(); |
||
| 194 | $html .= ' '; |
||
| 195 | $temp = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType='.get_class($this->record))."'", 'Back to List', 'cancelBut'); |
||
| 196 | $html .= $temp->render(); |
||
| 197 | $html .= '</td></tr>'; |
||
| 198 | |||
| 199 | $html .= View::renderSecurityFields(); |
||
| 200 | |||
| 201 | $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('_METHOD')) : '_METHOD'); |
||
| 202 | $html .= '<input type="hidden" name="'.$fieldname.'" id="'.$fieldname.'" value="PUT"/>'; |
||
| 203 | |||
| 204 | $html .= '</form></table>'; |
||
| 205 | } else { |
||
| 206 | $html .= '</table>'; |
||
| 207 | |||
| 208 | $html .= '<div align="center">'; |
||
| 209 | $temp = new Button('submit', 'Update Your Comment', 'saveBut'.$this->record->getID()); |
||
| 210 | $html .= $temp->render(); |
||
| 211 | $html .= '</div>'; |
||
| 212 | |||
| 213 | $html .= View::renderSecurityFields(); |
||
| 214 | |||
| 215 | $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('_METHOD')) : '_METHOD'); |
||
| 216 | $html .= '<input type="hidden" name="'.$fieldname.'" id="'.$fieldname.'" value="PUT"/>'; |
||
| 217 | |||
| 218 | $html .= '</form>'; |
||
| 219 | } |
||
| 220 | |||
| 221 | return $html; |
||
| 222 | } |
||
| 223 | } |
||
| 224 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: