| Conditions | 12 |
| Paths | 16 |
| Total Lines | 94 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 50 | public function ajaxAction(Request $request, ResourceNodeRepository $repo): Response |
||
| 51 | { |
||
| 52 | if (!api_protect_course_script(false)) { |
||
| 53 | exit; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** @var CChatConversationRepository $resourceRepo */ |
||
| 57 | $resourceRepo = $this->getRepository('chat', 'conversations'); |
||
| 58 | |||
| 59 | $courseId = api_get_course_int_id(); |
||
| 60 | $userId = api_get_user_id(); |
||
| 61 | $sessionId = api_get_session_id(); |
||
| 62 | $groupId = api_get_group_id(); |
||
| 63 | $json = ['status' => false]; |
||
| 64 | $parentResourceNode = $this->getParentResourceNode($request); |
||
| 65 | |||
| 66 | $courseChatUtils = new \CourseChatUtils( |
||
| 67 | $courseId, |
||
| 68 | $userId, |
||
| 69 | $sessionId, |
||
| 70 | $groupId, |
||
| 71 | $parentResourceNode, |
||
| 72 | $resourceRepo |
||
| 73 | ); |
||
| 74 | |||
| 75 | $action = $request->get('action'); |
||
| 76 | |||
| 77 | switch ($action) { |
||
| 78 | case 'chat_logout': |
||
| 79 | $logInfo = [ |
||
| 80 | 'tool' => TOOL_CHAT, |
||
| 81 | 'action' => 'exit', |
||
| 82 | 'action_details' => 'exit-chat', |
||
| 83 | ]; |
||
| 84 | Event::registerLog($logInfo); |
||
| 85 | |||
| 86 | break; |
||
| 87 | case 'track': |
||
| 88 | $courseChatUtils->keepUserAsConnected(); |
||
| 89 | $courseChatUtils->disconnectInactiveUsers(); |
||
| 90 | |||
| 91 | $friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; |
||
| 92 | //$filePath = $courseChatUtils->getFileName(true, $friend); |
||
| 93 | //$newFileSize = file_exists($filePath) ? filesize($filePath) : 0; |
||
| 94 | //$oldFileSize = isset($_GET['size']) ? (int) $_GET['size'] : -1; |
||
| 95 | $newUsersOnline = $courseChatUtils->countUsersOnline(); |
||
| 96 | $oldUsersOnline = isset($_GET['users_online']) ? (int) $_GET['users_online'] : 0; |
||
| 97 | |||
| 98 | $json = [ |
||
| 99 | 'status' => true, |
||
| 100 | 'data' => [ |
||
| 101 | //'oldFileSize' => file_exists($filePath) ? filesize($filePath) : 0, |
||
| 102 | 'oldFileSize' => false, |
||
| 103 | 'history' => $courseChatUtils->readMessages(false, $friend), |
||
| 104 | 'usersOnline' => $newUsersOnline, |
||
| 105 | 'userList' => $newUsersOnline != $oldUsersOnline ? $courseChatUtils->listUsersOnline() : null, |
||
| 106 | 'currentFriend' => $friend, |
||
| 107 | ], |
||
| 108 | ]; |
||
| 109 | |||
| 110 | break; |
||
| 111 | case 'preview': |
||
| 112 | $json = [ |
||
| 113 | 'status' => true, |
||
| 114 | 'data' => [ |
||
| 115 | 'message' => $courseChatUtils->prepareMessage($_REQUEST['message']), |
||
| 116 | ], |
||
| 117 | ]; |
||
| 118 | |||
| 119 | break; |
||
| 120 | case 'reset': |
||
| 121 | $friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; |
||
| 122 | |||
| 123 | $json = [ |
||
| 124 | 'status' => true, |
||
| 125 | 'data' => $courseChatUtils->readMessages(true, $friend), |
||
| 126 | ]; |
||
| 127 | |||
| 128 | break; |
||
| 129 | case 'write': |
||
| 130 | $friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; |
||
| 131 | $status = $courseChatUtils->saveMessage($_REQUEST['message'], $friend); |
||
| 132 | |||
| 133 | $json = [ |
||
| 134 | 'status' => $status, |
||
| 135 | 'data' => [ |
||
| 136 | 'writed' => $status, |
||
| 137 | ], |
||
| 138 | ]; |
||
| 139 | |||
| 140 | break; |
||
| 141 | } |
||
| 142 | |||
| 143 | return new JsonResponse($json); |
||
| 144 | } |
||
| 146 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.