Code Duplication    Length = 7-8 lines in 2 locations

components/Chat.php 2 locations

@@ 121-127 (lines=7) @@
118
            'user' => $joinedUser,
119
            'join' => true,
120
        ];
121
        foreach ($users as $user) {
122
            //send message for other users of this chat
123
            if ($userId != $user->getId()) {
124
                $conn = $this->clients[$user->getRid()];
125
                $conn->send(Json::encode(['type' => 'auth', 'data' => $response]));
126
            }
127
        }
128
        //send auth response for joined user
129
        $response = [
130
            'user' => $joinedUser,
@@ 157-164 (lines=8) @@
154
        $data['message']['timestamp'] = time();
155
        $user = $this->cm->getUserByRid($rid);
156
        $this->cm->storeMessage($user, $chat, $data['message']);
157
        foreach ($chat->getUsers() as $user) {
158
            //need not to send message for self
159
            if ($user->getRid() == $rid) {
160
                continue;
161
            }
162
            $conn = $this->clients[$user->getRid()];
163
            $conn->send(Json::encode(['type' => 'message', 'data' => $data]));
164
        }
165
    }
166
167
    /**