| Conditions | 7 |
| Paths | 64 |
| Total Lines | 82 |
| Code Lines | 28 |
| Lines | 4 |
| Ratio | 4.88 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 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 |
||
| 113 | public function editView($fields = array()) |
||
| 114 | { |
||
| 115 | if (method_exists($this, 'before_editView_callback')) { |
||
| 116 | $this->before_editView_callback(); |
||
| 117 | } |
||
| 118 | |||
| 119 | $config = ConfigProvider::getInstance(); |
||
| 120 | |||
| 121 | // the form action |
||
| 122 | if (isset($fields['URI'])) { |
||
| 123 | $fields['formAction'] = $fields['URI']; |
||
| 124 | } |
||
| 125 | |||
| 126 | // the form ID |
||
| 127 | $fields['formID'] = stripslashes(get_class($this->BO)).'_'.$this->BO->getID(); |
||
| 128 | |||
| 129 | // buffer form fields to $formFields |
||
| 130 | $fields['formFields'] = $this->renderAllFields('edit'); |
||
| 131 | |||
| 132 | // buffer HTML output for Create and Cancel buttons |
||
| 133 | $button = new Button('submit', 'Save', 'saveBut'); |
||
| 134 | $fields['saveButton'] = $button->render(); |
||
| 135 | |||
| 136 | $js = "if(window.jQuery) { |
||
| 137 | BootstrapDialog.show({ |
||
| 138 | title: 'Confirmation', |
||
| 139 | message: 'Are you sure you wish to delete this item?', |
||
| 140 | buttons: [ |
||
| 141 | { |
||
| 142 | icon: 'glyphicon glyphicon-remove', |
||
| 143 | label: 'Cancel', |
||
| 144 | cssClass: 'btn btn-default btn-xs', |
||
| 145 | action: function(dialogItself){ |
||
| 146 | dialogItself.close(); |
||
| 147 | } |
||
| 148 | }, |
||
| 149 | { |
||
| 150 | icon: 'glyphicon glyphicon-ok', |
||
| 151 | label: 'Okay', |
||
| 152 | cssClass: 'btn btn-default btn-xs', |
||
| 153 | action: function(dialogItself) { |
||
| 154 | $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordOID')) : 'ActiveRecordOID')."\"]').attr('value', '".$this->BO->getOID()."'); |
||
| 155 | $('#deleteForm').submit(); |
||
| 156 | dialogItself.close(); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | ] |
||
| 160 | }); |
||
| 161 | }"; |
||
| 162 | |||
| 163 | $button = new Button($js, 'Delete', 'deleteBut'); |
||
| 164 | $fields['deleteButton'] = $button->render(); |
||
| 165 | |||
| 166 | $button = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType='.get_class($this->BO).'&start=0&limit='.$config->get('app.list.page.amount'))."'", 'Back to List', 'cancelBut'); |
||
| 167 | $fields['cancelButton'] = $button->render(); |
||
| 168 | |||
| 169 | $tags = array(); |
||
| 170 | |||
| 171 | if (is_object($this->BO->getPropObject('tags'))) { |
||
| 172 | $tags = $this->BO->getPropObject('tags')->getRelatedObjects(); |
||
| 173 | } |
||
| 174 | |||
| 175 | View Code Duplication | if (count($tags) > 0) { |
|
| 176 | $button = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\TagController&ActiveRecordType='.get_class($this->BO).'&ActiveRecordOID='.$this->BO->getOID())."'", 'Edit Tags', 'tagsBut'); |
||
| 177 | $fields['tagsButton'] = $button->render(); |
||
| 178 | } |
||
| 179 | |||
| 180 | // buffer security fields to $formSecurityFields variable |
||
| 181 | $fields['formSecurityFields'] = $this->renderSecurityFields(); |
||
| 182 | |||
| 183 | // OID will need to be posted for optimistic lock checking |
||
| 184 | $fields['version_num'] = $this->BO->getVersionNumber(); |
||
| 185 | |||
| 186 | // file attachments section |
||
| 187 | $fields['fileAttachments'] = $this->renderFileUploadSection(); |
||
| 188 | |||
| 189 | if (method_exists($this, 'after_editView_callback')) { |
||
| 190 | $this->after_editView_callback(); |
||
| 191 | } |
||
| 192 | |||
| 193 | return $this->loadTemplate($this->BO, 'edit', $fields); |
||
| 194 | } |
||
| 195 | |||
| 280 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.