| Conditions | 6 |
| Paths | 14 |
| Total Lines | 61 |
| Code Lines | 46 |
| 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 |
||
| 80 | public function createAction(array $userData) |
||
| 81 | { |
||
| 82 | $request = symfonyRequest::createFromGlobals(); |
||
| 83 | $requestMethod = $request->getMethod(); |
||
| 84 | $strErrorDesc = $responseData = $strErrorHeader = ''; |
||
| 85 | |||
| 86 | if (strtoupper($requestMethod) === 'POST') { |
||
| 87 | if (empty($userData['folders_list'])) { |
||
| 88 | $this->sendOutput("", ['HTTP/1.1 204 No Content']); |
||
| 89 | } else { |
||
| 90 | // Is user allowed to create a folder |
||
| 91 | // We check if allowed_to_create |
||
| 92 | if ((int) $userData['allowed_to_create'] !== 1) { |
||
| 93 | $strErrorDesc = 'User is not allowed to create a folder'; |
||
| 94 | $strErrorHeader = 'HTTP/1.1 401 Unauthorized'; |
||
| 95 | } else { |
||
| 96 | // get parameters |
||
| 97 | $arrQueryStringParams = $this->getQueryStringParams(); |
||
| 98 | try { |
||
| 99 | $folderModel = new FolderModel(); |
||
| 100 | $arrFolder = $folderModel->createFolder( |
||
| 101 | (string) $arrQueryStringParams['title'], |
||
| 102 | (int) $arrQueryStringParams['parent_id'], |
||
| 103 | (int) $arrQueryStringParams['complexity'], |
||
| 104 | (int) $arrQueryStringParams['duration'], |
||
| 105 | (int) $arrQueryStringParams['create_auth_without'], |
||
| 106 | (int) $arrQueryStringParams['edit_auth_without'], |
||
| 107 | (string) $arrQueryStringParams['icon'], |
||
| 108 | (string) $arrQueryStringParams['icon_selected'], |
||
| 109 | (string) $arrQueryStringParams['access_rights'], |
||
| 110 | (int) $userData['is_admin'], |
||
| 111 | (array) explode(',', $userData['folders_list']), |
||
| 112 | (int) $userData['is_manager'], |
||
| 113 | (int) $userData['user_can_create_root_folder'], |
||
| 114 | (int) $userData['user_can_manage_all_users'], |
||
| 115 | (int) $userData['id'], |
||
| 116 | (string) $userData['roles'], |
||
| 117 | ); |
||
| 118 | |||
| 119 | $responseData = json_encode($arrFolder); |
||
| 120 | } catch (Error $e) { |
||
| 121 | $strErrorDesc = $e->getMessage() . ' Something went wrong! Please contact support.1'; |
||
| 122 | $strErrorHeader = 'HTTP/1.1 500 Internal Server Error'; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } |
||
| 126 | } else { |
||
| 127 | $strErrorDesc = 'Method not supported'; |
||
| 128 | $strErrorHeader = 'HTTP/1.1 422 Unprocessable Entity'; |
||
| 129 | } |
||
| 130 | |||
| 131 | // send output |
||
| 132 | if (empty($strErrorDesc) === true) { |
||
| 133 | $this->sendOutput( |
||
| 134 | $responseData, |
||
| 135 | ['Content-Type: application/json', 'HTTP/1.1 200 OK'] |
||
| 136 | ); |
||
| 137 | } else { |
||
| 138 | $this->sendOutput( |
||
| 139 | json_encode(['error' => $strErrorDesc]), |
||
| 140 | ['Content-Type: application/json', $strErrorHeader] |
||
| 141 | ); |
||
| 146 |