| Conditions | 12 |
| Paths | 16 |
| Total Lines | 100 |
| Code Lines | 62 |
| 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 |
||
| 54 | |||
| 55 | /** @var CChatConversationRepository $resourceRepo */ |
||
| 56 | $resourceRepo = $this->getRepository('chat', 'conversations'); |
||
| 57 | |||
| 58 | $courseId = api_get_course_int_id(); |
||
| 59 | $userId = api_get_user_id(); |
||
| 60 | $sessionId = api_get_session_id(); |
||
| 61 | $groupId = api_get_group_id(); |
||
| 62 | $json = [ |
||
| 63 | 'status' => false, |
||
| 64 | ]; |
||
| 65 | $parentResourceNode = $this->getParentResourceNode($request); |
||
| 66 | |||
| 67 | $courseChatUtils = new CourseChatUtils( |
||
| 68 | $courseId, |
||
| 69 | $userId, |
||
| 70 | $sessionId, |
||
| 71 | $groupId, |
||
| 72 | $parentResourceNode, |
||
| 73 | $resourceRepo |
||
| 74 | ); |
||
| 75 | |||
| 76 | $action = $request->get('action'); |
||
| 77 | |||
| 78 | switch ($action) { |
||
| 79 | case 'chat_logout': |
||
| 80 | $logInfo = [ |
||
| 81 | 'tool' => TOOL_CHAT, |
||
| 82 | 'action' => 'exit', |
||
| 83 | 'action_details' => 'exit-chat', |
||
| 84 | ]; |
||
| 85 | Event::registerLog($logInfo); |
||
| 86 | |||
| 87 | break; |
||
| 88 | |||
| 89 | case 'track': |
||
| 90 | $courseChatUtils->keepUserAsConnected(); |
||
| 91 | $courseChatUtils->disconnectInactiveUsers(); |
||
| 92 | |||
| 93 | $friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; |
||
| 94 | // $filePath = $courseChatUtils->getFileName(true, $friend); |
||
| 95 | // $newFileSize = file_exists($filePath) ? filesize($filePath) : 0; |
||
| 96 | // $oldFileSize = isset($_GET['size']) ? (int) $_GET['size'] : -1; |
||
| 97 | $newUsersOnline = $courseChatUtils->countUsersOnline(); |
||
| 98 | $oldUsersOnline = isset($_GET['users_online']) ? (int) $_GET['users_online'] : 0; |
||
| 99 | |||
| 100 | $json = [ |
||
| 101 | 'status' => true, |
||
| 102 | 'data' => [ |
||
| 103 | // 'oldFileSize' => file_exists($filePath) ? filesize($filePath) : 0, |
||
| 104 | 'oldFileSize' => false, |
||
| 105 | 'history' => $courseChatUtils->readMessages(false, $friend), |
||
| 106 | 'usersOnline' => $newUsersOnline, |
||
| 107 | 'userList' => $newUsersOnline !== $oldUsersOnline ? $courseChatUtils->listUsersOnline() : null, |
||
| 108 | 'currentFriend' => $friend, |
||
| 109 | ], |
||
| 110 | ]; |
||
| 111 | |||
| 112 | break; |
||
| 113 | |||
| 114 | case 'preview': |
||
| 115 | $json = [ |
||
| 116 | 'status' => true, |
||
| 117 | 'data' => [ |
||
| 118 | 'message' => $courseChatUtils->prepareMessage($_REQUEST['message']), |
||
| 119 | ], |
||
| 120 | ]; |
||
| 121 | |||
| 122 | break; |
||
| 123 | |||
| 124 | case 'reset': |
||
| 125 | $friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; |
||
| 126 | |||
| 127 | $json = [ |
||
| 128 | 'status' => true, |
||
| 129 | 'data' => $courseChatUtils->readMessages(true, $friend), |
||
| 130 | ]; |
||
| 131 | |||
| 132 | break; |
||
| 133 | |||
| 134 | case 'write': |
||
| 135 | $friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; |
||
| 136 | $status = $courseChatUtils->saveMessage($_REQUEST['message'], $friend); |
||
| 137 | |||
| 138 | $json = [ |
||
| 139 | 'status' => $status, |
||
| 140 | 'data' => [ |
||
| 141 | 'writed' => $status, |
||
| 142 | ], |
||
| 143 | ]; |
||
| 144 | |||
| 145 | break; |
||
| 146 | } |
||
| 147 | |||
| 148 | return new JsonResponse($json); |
||
| 149 | } |
||
| 150 | } |
||
| 151 |
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.