| Conditions | 7 |
| Paths | 16 |
| Total Lines | 54 |
| Code Lines | 33 |
| Lines | 15 |
| Ratio | 27.78 % |
| 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 |
||
| 107 | public function editPost(\Base $f3) |
||
| 108 | { |
||
| 109 | $this->csrf('@admin_apps_list'); |
||
| 110 | $this->redirectLoggedOutUser(); |
||
| 111 | |||
| 112 | if (false == $f3->get('isRoot')) { |
||
| 113 | $this->notify(_('You do not have (root) permission!'), 'error'); |
||
| 114 | return $f3->reroute('@admin'); |
||
| 115 | } |
||
| 116 | |||
| 117 | $oAuth2Model = Models\OAuth2::instance(); |
||
| 118 | $appsMapper = $oAuth2Model->getAppsMapper(); |
||
| 119 | |||
| 120 | // filter input vars of request, set back into REQUEST |
||
| 121 | $appsMapper->copyfrom($f3->get('REQUEST')); |
||
| 122 | $data = $appsMapper->filter(); |
||
| 123 | $request = $f3->get('REQUEST'); |
||
| 124 | foreach ($data as $k => $v) { |
||
| 125 | if (array_key_exists($k, $request)) { |
||
| 126 | $f3->set('REQUEST.' . $k, $v); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | // check app name exists |
||
| 131 | View Code Duplication | if (!$appsMapper->load(['LOWER(client_id) = LOWER(?) AND users_uuid = ?', |
|
| 132 | $request['client_id'], $f3->get('uuid')])) { |
||
| 133 | $this->notify(_('The app does not exist!'), 'warning'); |
||
| 134 | $f3->reroute('@api_apps'); |
||
| 135 | return; |
||
| 136 | } |
||
| 137 | |||
| 138 | // check required fields |
||
| 139 | $appsMapper->copyfrom($f3->get('REQUEST')); |
||
| 140 | $appsMapper->validationRequired([ |
||
| 141 | 'name', |
||
| 142 | 'description', |
||
| 143 | 'callback_uri', |
||
| 144 | 'status', |
||
| 145 | ]); |
||
| 146 | |||
| 147 | // at this point the app can be validated |
||
| 148 | View Code Duplication | if (true !== $appsMapper->validate()) { |
|
| 149 | $this->notify(['info' => $appsMapper->validationErrors($appsMapper->validate(false))]); |
||
| 150 | $f3->reroute('@api_apps'); |
||
| 151 | } |
||
| 152 | |||
| 153 | View Code Duplication | if ($appsMapper->save()) { |
|
| 154 | $this->notify(_('The app has been updated!'), 'success'); |
||
| 155 | } else { |
||
| 156 | $this->notify(_('App update failed!'), 'error'); |
||
| 157 | } |
||
| 158 | |||
| 159 | $f3->reroute('@admin_apps_list'); |
||
| 160 | } |
||
| 161 | |||
| 190 |