@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require (dirname(__DIR__) . '/vendor/autoload.php'); |
|
3 | +require (dirname(__DIR__).'/vendor/autoload.php'); |
|
4 | 4 | use ChatApp\Login; |
5 | 5 | |
6 | -if(isset($_POST['q'])) |
|
6 | +if (isset($_POST['q'])) |
|
7 | 7 | { |
8 | 8 | $loginField = json_decode($_POST['q']); |
9 | 9 | $login = $loginField->login; |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | 'passLogin' => $password |
15 | 15 | ); |
16 | 16 | $result = $obLogin->authLogin($data); |
17 | - if(isset($result)) |
|
17 | + if (isset($result)) |
|
18 | 18 | echo $result; |
19 | 19 | else |
20 | 20 | echo json_encode([]); |
@@ -14,8 +14,9 @@ |
||
14 | 14 | 'passLogin' => $password |
15 | 15 | ); |
16 | 16 | $result = $obLogin->authLogin($data); |
17 | - if(isset($result)) |
|
18 | - echo $result; |
|
19 | - else |
|
20 | - echo json_encode([]); |
|
21 | -} |
|
22 | 17 | \ No newline at end of file |
18 | + if(isset($result)) { |
|
19 | + echo $result; |
|
20 | + } else { |
|
21 | + echo json_encode([]); |
|
22 | + } |
|
23 | + } |
|
23 | 24 | \ No newline at end of file |
@@ -5,25 +5,25 @@ |
||
5 | 5 | |
6 | 6 | if(isset($_POST['q'])) |
7 | 7 | { |
8 | - $registerField = json_decode($_POST['q']); |
|
9 | - $name = $registerField->name; |
|
10 | - $email = $registerField->email; |
|
11 | - $username = $registerField->username; |
|
12 | - $mob = $registerField->mob; |
|
13 | - $password = $registerField->password; |
|
14 | - $obRegister = new Register(); |
|
15 | - $data = array( |
|
16 | - 'name' => $name, |
|
17 | - 'email' => $email, |
|
18 | - 'username' => $username, |
|
19 | - 'passRegister' => $password, |
|
20 | - 'mob' => $mob |
|
21 | - ); |
|
22 | - $result = $obRegister->authRegister($data); |
|
23 | - if(isset($result)) |
|
24 | - echo $result; |
|
25 | - else |
|
26 | - echo json_encode([]); |
|
8 | + $registerField = json_decode($_POST['q']); |
|
9 | + $name = $registerField->name; |
|
10 | + $email = $registerField->email; |
|
11 | + $username = $registerField->username; |
|
12 | + $mob = $registerField->mob; |
|
13 | + $password = $registerField->password; |
|
14 | + $obRegister = new Register(); |
|
15 | + $data = array( |
|
16 | + 'name' => $name, |
|
17 | + 'email' => $email, |
|
18 | + 'username' => $username, |
|
19 | + 'passRegister' => $password, |
|
20 | + 'mob' => $mob |
|
21 | + ); |
|
22 | + $result = $obRegister->authRegister($data); |
|
23 | + if(isset($result)) |
|
24 | + echo $result; |
|
25 | + else |
|
26 | + echo json_encode([]); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require (dirname(__DIR__) . '/vendor/autoload.php'); |
|
3 | +require (dirname(__DIR__).'/vendor/autoload.php'); |
|
4 | 4 | use ChatApp\Register; |
5 | 5 | |
6 | -if(isset($_POST['q'])) |
|
6 | +if (isset($_POST['q'])) |
|
7 | 7 | { |
8 | 8 | $registerField = json_decode($_POST['q']); |
9 | 9 | $name = $registerField->name; |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | 'mob' => $mob |
21 | 21 | ); |
22 | 22 | $result = $obRegister->authRegister($data); |
23 | - if(isset($result)) |
|
23 | + if (isset($result)) |
|
24 | 24 | echo $result; |
25 | 25 | else |
26 | 26 | echo json_encode([]); |
@@ -20,11 +20,12 @@ |
||
20 | 20 | 'mob' => $mob |
21 | 21 | ); |
22 | 22 | $result = $obRegister->authRegister($data); |
23 | - if(isset($result)) |
|
24 | - echo $result; |
|
25 | - else |
|
26 | - echo json_encode([]); |
|
27 | -} |
|
23 | + if(isset($result)) { |
|
24 | + echo $result; |
|
25 | + } else { |
|
26 | + echo json_encode([]); |
|
27 | + } |
|
28 | + } |
|
28 | 29 | |
29 | 30 | |
30 | 31 |
@@ -175,6 +175,6 @@ |
||
175 | 175 | <?php |
176 | 176 | } |
177 | 177 | else{ |
178 | - header('Location:'. getenv('APP_URL')."/index.php"); |
|
178 | + header('Location:'. getenv('APP_URL')."/index.php"); |
|
179 | 179 | } |
180 | 180 | ?> |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once (dirname(__DIR__) . '/vendor/autoload.php'); |
|
3 | +require_once (dirname(__DIR__).'/vendor/autoload.php'); |
|
4 | 4 | use ChatApp\Session; |
5 | 5 | use Dotenv\Dotenv; |
6 | 6 | $dotenv = new Dotenv(dirname(__DIR__)); |
7 | 7 | $dotenv->load(); |
8 | 8 | |
9 | -if(Session::get('start') != null && empty($_GET['user'])) |
|
9 | +if (Session::get('start') != null && empty($_GET['user'])) |
|
10 | 10 | { |
11 | 11 | |
12 | 12 | ?> |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | |
175 | 175 | <?php |
176 | 176 | } |
177 | -else{ |
|
178 | - header('Location:'. getenv('APP_URL')."/index.php"); |
|
177 | +else { |
|
178 | + header('Location:'.getenv('APP_URL')."/index.php"); |
|
179 | 179 | } |
180 | 180 | ?> |
@@ -168,8 +168,7 @@ |
||
168 | 168 | </html> |
169 | 169 | |
170 | 170 | <?php |
171 | -} |
|
172 | -else{ |
|
171 | +} else{ |
|
173 | 172 | header('Location:'. getenv('APP_URL')."/index.php"); |
174 | 173 | } |
175 | 174 | ?> |
@@ -51,9 +51,9 @@ discard block |
||
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | - * @depends test_authRegister |
|
55 | - * Testing for the register with empty username |
|
56 | - */ |
|
54 | + * @depends test_authRegister |
|
55 | + * Testing for the register with empty username |
|
56 | + */ |
|
57 | 57 | public function test_authregisterEmptyUsername() |
58 | 58 | { |
59 | 59 | $output = $this->obRegister->authregister( |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | - * @depends test_authRegister |
|
81 | - * Testing for the register with invalid email credentials |
|
82 | - */ |
|
80 | + * @depends test_authRegister |
|
81 | + * Testing for the register with invalid email credentials |
|
82 | + */ |
|
83 | 83 | public function test_authregisterInvalidEmail() |
84 | 84 | { |
85 | 85 | $output = $this->obRegister->authregister( |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
106 | - * @depends test_authRegister |
|
107 | - * Testing for the register with repeated credentials |
|
108 | - */ |
|
106 | + * @depends test_authRegister |
|
107 | + * Testing for the register with repeated credentials |
|
108 | + */ |
|
109 | 109 | public function test_authregisterInvalidCredentials() |
110 | 110 | { |
111 | 111 | $output = $this->obRegister->authregister( |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
140 | - * @depends test_authRegister |
|
141 | - * Testing for the login with correct credentials |
|
142 | - */ |
|
140 | + * @depends test_authRegister |
|
141 | + * Testing for the login with correct credentials |
|
142 | + */ |
|
143 | 143 | |
144 | 144 | public function test_authLogin() |
145 | 145 | { |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * @depends test_authRegister |
|
167 | - * Testing for the login with empty credentials |
|
168 | - */ |
|
166 | + * @depends test_authRegister |
|
167 | + * Testing for the login with empty credentials |
|
168 | + */ |
|
169 | 169 | |
170 | 170 | public function test_authLoginEmptyValues() |
171 | 171 | { |
@@ -191,9 +191,9 @@ discard block |
||
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
194 | - * @depends test_authRegister |
|
195 | - * Testing for the login with invalid or wrong email |
|
196 | - */ |
|
194 | + * @depends test_authRegister |
|
195 | + * Testing for the login with invalid or wrong email |
|
196 | + */ |
|
197 | 197 | |
198 | 198 | public function test_authLoginWrongEmail() |
199 | 199 | { |
@@ -215,9 +215,9 @@ discard block |
||
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
218 | - * @depends test_authRegister |
|
219 | - * Testing for the login with invalid email credentials |
|
220 | - */ |
|
218 | + * @depends test_authRegister |
|
219 | + * Testing for the login with invalid email credentials |
|
220 | + */ |
|
221 | 221 | public function test_authLoginInvalidUsernameEmail() |
222 | 222 | { |
223 | 223 | $output = $this->obLogin->authLogin( |
@@ -238,9 +238,9 @@ discard block |
||
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
241 | - * @depends test_authRegister |
|
242 | - * Testing for the login with invalid password credentials |
|
243 | - */ |
|
241 | + * @depends test_authRegister |
|
242 | + * Testing for the login with invalid password credentials |
|
243 | + */ |
|
244 | 244 | public function test_authLoginInvalidPassword() |
245 | 245 | { |
246 | 246 | $output = $this->obLogin->authLogin( |
@@ -260,9 +260,9 @@ discard block |
||
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
263 | - * @depends test_authRegister |
|
264 | - * Testing for the Profile::class with valid login_id |
|
265 | - */ |
|
263 | + * @depends test_authRegister |
|
264 | + * Testing for the Profile::class with valid login_id |
|
265 | + */ |
|
266 | 266 | public function test_getProfile() |
267 | 267 | { |
268 | 268 | $output = Profile::getProfile(1); |
@@ -275,9 +275,9 @@ discard block |
||
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
278 | - * @depends test_authRegister |
|
279 | - * Testing for the Profile::class with invalid login_id |
|
280 | - */ |
|
278 | + * @depends test_authRegister |
|
279 | + * Testing for the Profile::class with invalid login_id |
|
280 | + */ |
|
281 | 281 | public function test_getProfileInvalidID() |
282 | 282 | { |
283 | 283 | $output = Profile::getProfile(0); |
@@ -285,9 +285,9 @@ discard block |
||
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
288 | - * @depends test_authRegister |
|
289 | - * Testing for the User::class with valid login_id |
|
290 | - */ |
|
288 | + * @depends test_authRegister |
|
289 | + * Testing for the User::class with valid login_id |
|
290 | + */ |
|
291 | 291 | public function test_userDetails() |
292 | 292 | { |
293 | 293 | $expectedOutput = [ |
@@ -306,9 +306,9 @@ discard block |
||
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
309 | - * @depends test_authRegister |
|
310 | - * Testing for the User::class with invalid data |
|
311 | - */ |
|
309 | + * @depends test_authRegister |
|
310 | + * Testing for the User::class with invalid data |
|
311 | + */ |
|
312 | 312 | public function test_userDetailsInvalidID() |
313 | 313 | { |
314 | 314 | $output = $this->obUser->userDetails(0, True); |
@@ -316,9 +316,9 @@ discard block |
||
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
319 | - * @depends test_authRegister |
|
320 | - * Testing for the Validate::class for email |
|
321 | - */ |
|
319 | + * @depends test_authRegister |
|
320 | + * Testing for the Validate::class for email |
|
321 | + */ |
|
322 | 322 | public function test_validateEmailInDb() |
323 | 323 | { |
324 | 324 | $output = $this->obValidate->validateEmailInDb('[email protected]'); |
@@ -326,9 +326,9 @@ discard block |
||
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
329 | - * @depends test_authRegister |
|
330 | - * Testing for the Validate::class for username |
|
331 | - */ |
|
329 | + * @depends test_authRegister |
|
330 | + * Testing for the Validate::class for username |
|
331 | + */ |
|
332 | 332 | public function test_validateUsernameInDb() |
333 | 333 | { |
334 | 334 | $output = $this->obValidate->validateUsernameInDb('test'); |
@@ -336,9 +336,9 @@ discard block |
||
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
339 | - * @depends test_authRegister |
|
340 | - * Testing for the Validate::class for non-existing username |
|
341 | - */ |
|
339 | + * @depends test_authRegister |
|
340 | + * Testing for the Validate::class for non-existing username |
|
341 | + */ |
|
342 | 342 | public function test_validateUsernameInDbNot() |
343 | 343 | { |
344 | 344 | $output = $this->obValidate->validateUsernameInDb('abc'); |
@@ -346,9 +346,9 @@ discard block |
||
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
349 | - * @depends test_authRegister |
|
350 | - * Testing for the Validate::class for non-existing email |
|
351 | - */ |
|
349 | + * @depends test_authRegister |
|
350 | + * Testing for the Validate::class for non-existing email |
|
351 | + */ |
|
352 | 352 | public function test_validateEmailInDbNot() |
353 | 353 | { |
354 | 354 | $output = $this->obValidate->validateEmailInDb('[email protected]'); |
@@ -356,9 +356,9 @@ discard block |
||
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
359 | - * @depends test_authRegister |
|
360 | - * Testing for the Online::class |
|
361 | - */ |
|
359 | + * @depends test_authRegister |
|
360 | + * Testing for the Online::class |
|
361 | + */ |
|
362 | 362 | public function test_Online() |
363 | 363 | { |
364 | 364 | Online::setOnlineStatus(1); |
@@ -373,9 +373,9 @@ discard block |
||
373 | 373 | |
374 | 374 | |
375 | 375 | /** |
376 | - * @depends test_Online |
|
377 | - * Empty the DB |
|
378 | - */ |
|
376 | + * @depends test_Online |
|
377 | + * Empty the DB |
|
378 | + */ |
|
379 | 379 | public function test_EmptyDB() |
380 | 380 | { |
381 | 381 | $connect = mysqli_connect( |
@@ -25,6 +25,9 @@ discard block |
||
25 | 25 | Online::setOnlineStatus($conn->userId); |
26 | 26 | } |
27 | 27 | |
28 | + /** |
|
29 | + * @param ConnectionInterface $conn |
|
30 | + */ |
|
28 | 31 | public function setID($conn) |
29 | 32 | { |
30 | 33 | session_id($conn->WebSocket->request->getCookies()['PHPSESSID']); |
@@ -136,12 +139,20 @@ discard block |
||
136 | 139 | return $obSidebar->loadSideBar($data); |
137 | 140 | } |
138 | 141 | |
142 | + /** |
|
143 | + * @param string $data |
|
144 | + * @param boolean $para |
|
145 | + */ |
|
139 | 146 | public function onConversation($data, $para) |
140 | 147 | { |
141 | 148 | $obConversation = new Conversation(); |
142 | 149 | return $obConversation->conversationLoad($data, $para); |
143 | 150 | } |
144 | 151 | |
152 | + /** |
|
153 | + * @param string $data |
|
154 | + * @param boolean $para |
|
155 | + */ |
|
145 | 156 | public function onReceiver($data, $para) |
146 | 157 | { |
147 | 158 | $obReceiver = new Receiver(); |
@@ -36,13 +36,13 @@ discard block |
||
36 | 36 | |
37 | 37 | public function onMessage(ConnectionInterface $from, $msg) |
38 | 38 | { |
39 | - $msg = (object) json_decode($msg); |
|
40 | - if($msg->type == 'OpenChat initiated..!') |
|
39 | + $msg = (object)json_decode($msg); |
|
40 | + if ($msg->type == 'OpenChat initiated..!') |
|
41 | 41 | { |
42 | - $initial = (object) array(); |
|
42 | + $initial = (object)array(); |
|
43 | 43 | $initial->initial = json_decode($this->onSidebar($from->userId)); |
44 | 44 | |
45 | - if($initial->initial != null) |
|
45 | + if ($initial->initial != null) |
|
46 | 46 | { |
47 | 47 | $initial->conversation = json_decode( |
48 | 48 | $this->onConversation( |
@@ -58,14 +58,14 @@ discard block |
||
58 | 58 | } |
59 | 59 | elseif ($msg->type == 'Load Sidebar') |
60 | 60 | { |
61 | - $sidebar = (object) array(); |
|
61 | + $sidebar = (object)array(); |
|
62 | 62 | $sidebar->sidebar = json_decode($this->onSidebar($from->userId)); |
63 | 63 | $from->send(json_encode($sidebar)); |
64 | 64 | } |
65 | 65 | elseif ($msg->type == 'Initiated') |
66 | 66 | { |
67 | 67 | $msg->userId = $from->userId; |
68 | - $result = (object) array(); |
|
68 | + $result = (object)array(); |
|
69 | 69 | $result->conversation = json_decode($this->onConversation(json_encode($msg), False)); |
70 | 70 | $from->send(json_encode($result)); |
71 | 71 | } |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | $getReturn = $this->onReply($msg); |
88 | 88 | echo $getReturn; |
89 | 89 | |
90 | - $receiveResult = (object) array(); |
|
91 | - $sentResult = (object) array(); |
|
90 | + $receiveResult = (object)array(); |
|
91 | + $sentResult = (object)array(); |
|
92 | 92 | foreach ($this->clients as $client) |
93 | 93 | { |
94 | 94 | if ($client->userId == $msg->name) |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | $client->send(json_encode($receiveResult)); |
109 | 109 | } |
110 | - elseif($client == $from) |
|
110 | + elseif ($client == $from) |
|
111 | 111 | { |
112 | 112 | $sentResult->sidebar = json_decode($this->onSidebar($client->userId)); |
113 | 113 |
@@ -2,11 +2,9 @@ |
||
2 | 2 | namespace ChatApp; |
3 | 3 | use Ratchet\MessageComponentInterface; |
4 | 4 | use Ratchet\ConnectionInterface; |
5 | -use ChatApp\Models\Message; |
|
6 | 5 | use ChatApp\Reply; |
7 | 6 | use ChatApp\Conversation; |
8 | 7 | use ChatApp\Receiver; |
9 | -use ChatApp\SideBar; |
|
10 | 8 | use ChatApp\Search; |
11 | 9 | use ChatApp\Compose; |
12 | 10 | use ChatApp\Online; |
@@ -55,33 +55,28 @@ discard block |
||
55 | 55 | ); |
56 | 56 | } |
57 | 57 | $from->send(json_encode($initial)); |
58 | - } |
|
59 | - elseif ($msg->type == 'Load Sidebar') |
|
58 | + } elseif ($msg->type == 'Load Sidebar') |
|
60 | 59 | { |
61 | 60 | $sidebar = (object) array(); |
62 | 61 | $sidebar->sidebar = json_decode($this->onSidebar($from->userId)); |
63 | 62 | $from->send(json_encode($sidebar)); |
64 | - } |
|
65 | - elseif ($msg->type == 'Initiated') |
|
63 | + } elseif ($msg->type == 'Initiated') |
|
66 | 64 | { |
67 | 65 | $msg->userId = $from->userId; |
68 | 66 | $result = (object) array(); |
69 | 67 | $result->conversation = json_decode($this->onConversation(json_encode($msg), False)); |
70 | 68 | $from->send(json_encode($result)); |
71 | - } |
|
72 | - elseif ($msg->type == 'Search') |
|
69 | + } elseif ($msg->type == 'Search') |
|
73 | 70 | { |
74 | 71 | $msg->userId = $from->userId; |
75 | 72 | $searchResult = $this->onSearch($msg); |
76 | 73 | $from->send($searchResult); |
77 | - } |
|
78 | - elseif ($msg->type == 'Compose') |
|
74 | + } elseif ($msg->type == 'Compose') |
|
79 | 75 | { |
80 | 76 | $msg->userId = $from->userId; |
81 | 77 | $composeResult = $this->onCompose($msg); |
82 | 78 | $from->send($composeResult); |
83 | - } |
|
84 | - else |
|
79 | + } else |
|
85 | 80 | { |
86 | 81 | $msg->userId = $from->userId; |
87 | 82 | $msg->name = convert_uudecode(hex2bin($msg->name)); |
@@ -108,8 +103,7 @@ discard block |
||
108 | 103 | ); |
109 | 104 | |
110 | 105 | $client->send(json_encode($receiveResult)); |
111 | - } |
|
112 | - elseif($client == $from) |
|
106 | + } elseif($client == $from) |
|
113 | 107 | { |
114 | 108 | $sentResult->sidebar = json_decode($this->onSidebar($client->userId)); |
115 | 109 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | namespace ChatApp; |
4 | -require_once (dirname(__DIR__) . '/vendor/autoload.php'); |
|
4 | +require_once (dirname(__DIR__).'/vendor/autoload.php'); |
|
5 | 5 | use ChatApp\Time; |
6 | 6 | use Dotenv\Dotenv; |
7 | 7 | $dotenv = new Dotenv(dirname(__DIR__)); |
@@ -34,20 +34,20 @@ discard block |
||
34 | 34 | $userId = $suggestion->userId; |
35 | 35 | $suggestion = trim($suggestion->value); |
36 | 36 | $flag = 0; |
37 | - if(!empty($userId) && !empty($suggestion)) |
|
37 | + if (!empty($userId) && !empty($suggestion)) |
|
38 | 38 | { |
39 | 39 | $query = "SELECT * FROM login where login_id != '$userId' and name like '$suggestion%' ORDER BY name DESC"; |
40 | - if($result = $this->connect->query($query)) |
|
40 | + if ($result = $this->connect->query($query)) |
|
41 | 41 | { |
42 | - if($result->num_rows > 0) |
|
42 | + if ($result->num_rows > 0) |
|
43 | 43 | { |
44 | - while($row = $result->fetch_assoc()) |
|
44 | + while ($row = $result->fetch_assoc()) |
|
45 | 45 | { |
46 | 46 | $check_id = $row["login_id"]; |
47 | 47 | $query = "SELECT * from total_message where (user1 = '$check_id' and user2 = '$userId') or (user2 = '$check_id' and user1 = '$userId')"; |
48 | - if($result1 = $this->connect->query($query)) |
|
48 | + if ($result1 = $this->connect->query($query)) |
|
49 | 49 | { |
50 | - if($result1->num_rows > 0) |
|
50 | + if ($result1->num_rows > 0) |
|
51 | 51 | { |
52 | 52 | $fetch = $result1->fetch_assoc(); |
53 | 53 | $fetch['time'] = $this->obTime->timeConversion($fetch['time']); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | } |
60 | 60 | } |
61 | 61 | } |
62 | - if($flag != 0) |
|
62 | + if ($flag != 0) |
|
63 | 63 | { |
64 | 64 | $this->array = array_merge([], ["Search" => $this->array]); |
65 | 65 | return json_encode($this->array); |
@@ -26,19 +26,22 @@ discard block |
||
26 | 26 | |
27 | 27 | public function replyTo($msg) |
28 | 28 | { |
29 | - if(!empty($msg)) //checks for the value send |
|
29 | + if(!empty($msg)) { |
|
30 | + //checks for the value send |
|
30 | 31 | { |
31 | 32 | $userId = $msg->userId; |
33 | + } |
|
32 | 34 | $receiverID = $msg->name; //stores id of the person whom message is to be sent |
33 | 35 | $identifier = ""; |
34 | 36 | |
35 | - if($receiverID > $userId) // geneate specific unique code to store messages |
|
37 | + if($receiverID > $userId) { |
|
38 | + // geneate specific unique code to store messages |
|
36 | 39 | { |
37 | 40 | $user1 = $userId; |
41 | + } |
|
38 | 42 | $user2 = $receiverID; |
39 | 43 | $identifier = $userId . ":" . $receiverID; |
40 | - } |
|
41 | - else |
|
44 | + } else |
|
42 | 45 | { |
43 | 46 | $user1 = $receiverID; |
44 | 47 | $user2 = $userId; |
@@ -57,19 +60,22 @@ discard block |
||
57 | 60 | $query = "SELECT * from login where login_id = '$receiverID'"; |
58 | 61 | |
59 | 62 | $result = $this->connect->query($query); |
60 | - if($result->num_rows > 0) // if true |
|
63 | + if($result->num_rows > 0) { |
|
64 | + // if true |
|
61 | 65 | { |
62 | 66 | //check whether he is sending message for thr first time or he has sent messages before |
63 | 67 | $query = "SELECT * from total_message where identifier = '$identifier'"; |
68 | + } |
|
64 | 69 | $result = $this->connect->query($query); |
65 | - if($result->num_rows > 0) // if he has sent messages before |
|
70 | + if($result->num_rows > 0) { |
|
71 | + // if he has sent messages before |
|
66 | 72 | { |
67 | 73 | // Update Total_Message Table |
68 | 74 | $query = "UPDATE total_message SET total_messages = total_messages+1, time = '$time', unread = 1, id = '$time_id' WHERE identifier = '$identifier'"; |
75 | + } |
|
69 | 76 | return $this->updateMessages($query, $identifier, $reply, $userId, $time); |
70 | 77 | |
71 | - } |
|
72 | - else // if he sends message for the first time |
|
78 | + } else // if he sends message for the first time |
|
73 | 79 | { |
74 | 80 | // insert Details in Total_Message Table |
75 | 81 | $query = "INSERT into total_message values('$identifier', 1, '$user1', '$user2', 1, '$time', '$time_id')"; |
@@ -82,6 +82,11 @@ |
||
82 | 82 | return "Failed"; |
83 | 83 | } |
84 | 84 | |
85 | + /** |
|
86 | + * @param string $identifier |
|
87 | + * @param string $reply |
|
88 | + * @param string $time |
|
89 | + */ |
|
85 | 90 | public function updateMessages($query, $identifier, $reply, $userId, $time) |
86 | 91 | { |
87 | 92 | if($result = $this->connect->query($query)) |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | namespace ChatApp; |
4 | -require_once (dirname(__DIR__) . '/vendor/autoload.php'); |
|
4 | +require_once (dirname(__DIR__).'/vendor/autoload.php'); |
|
5 | 5 | use Dotenv\Dotenv; |
6 | 6 | $dotenv = new Dotenv(dirname(__DIR__)); |
7 | 7 | $dotenv->load(); |
@@ -26,43 +26,43 @@ discard block |
||
26 | 26 | |
27 | 27 | public function replyTo($msg) |
28 | 28 | { |
29 | - if(!empty($msg)) //checks for the value send |
|
29 | + if (!empty($msg)) //checks for the value send |
|
30 | 30 | { |
31 | 31 | $userId = $msg->userId; |
32 | 32 | $receiverID = $msg->name; //stores id of the person whom message is to be sent |
33 | 33 | $identifier = ""; |
34 | 34 | |
35 | - if($receiverID > $userId) // geneate specific unique code to store messages |
|
35 | + if ($receiverID > $userId) // geneate specific unique code to store messages |
|
36 | 36 | { |
37 | 37 | $user1 = $userId; |
38 | 38 | $user2 = $receiverID; |
39 | - $identifier = $userId . ":" . $receiverID; |
|
39 | + $identifier = $userId.":".$receiverID; |
|
40 | 40 | } |
41 | 41 | else |
42 | 42 | { |
43 | 43 | $user1 = $receiverID; |
44 | 44 | $user2 = $userId; |
45 | - $identifier = $receiverID . ":" . $userId; |
|
45 | + $identifier = $receiverID.":".$userId; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | $reply = addslashes(trim($msg->reply)); // stores the message sent by the user. |
49 | 49 | |
50 | - $time = date("D d M Y H:i:s", time() + 16200); // current time |
|
50 | + $time = date("D d M Y H:i:s", time() + 16200); // current time |
|
51 | 51 | $time_id = date("YmdHis", time() + 16200); //to sort the array on the basis of time |
52 | 52 | |
53 | 53 | //the sender id must not be equal to current session id |
54 | - if($reply != "" && $receiverID != $userId) |
|
54 | + if ($reply != "" && $receiverID != $userId) |
|
55 | 55 | { |
56 | 56 | // check whether the receiver is authorized or registered |
57 | 57 | $query = "SELECT * from login where login_id = '$receiverID'"; |
58 | 58 | |
59 | 59 | $result = $this->connect->query($query); |
60 | - if($result->num_rows > 0) // if true |
|
60 | + if ($result->num_rows > 0) // if true |
|
61 | 61 | { |
62 | 62 | //check whether he is sending message for thr first time or he has sent messages before |
63 | 63 | $query = "SELECT * from total_message where identifier = '$identifier'"; |
64 | 64 | $result = $this->connect->query($query); |
65 | - if($result->num_rows > 0) // if he has sent messages before |
|
65 | + if ($result->num_rows > 0) // if he has sent messages before |
|
66 | 66 | { |
67 | 67 | // Update Total_Message Table |
68 | 68 | $query = "UPDATE total_message SET total_messages = total_messages+1, time = '$time', unread = 1, id = '$time_id' WHERE identifier = '$identifier'"; |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | return $this->updateMessages($query, $identifier, $reply, $userId, $time); |
77 | 77 | } |
78 | 78 | } |
79 | - return "Invalid Authentication"; // if he is unauthorized echo message is failed |
|
79 | + return "Invalid Authentication"; // if he is unauthorized echo message is failed |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | return "Failed"; |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | |
85 | 85 | public function updateMessages($query, $identifier, $reply, $userId, $time) |
86 | 86 | { |
87 | - if($result = $this->connect->query($query)) |
|
87 | + if ($result = $this->connect->query($query)) |
|
88 | 88 | { |
89 | 89 | //insert message in db |
90 | 90 | $query = "INSERT into messages values('$identifier', '$reply', '$userId', '$time', null)"; |
91 | - if($this->connect->query($query)) |
|
91 | + if ($this->connect->query($query)) |
|
92 | 92 | { |
93 | - return "Messages is sent"; // if query is executed return true |
|
93 | + return "Messages is sent"; // if query is executed return true |
|
94 | 94 | } |
95 | 95 | return "Message is failed"; |
96 | 96 | } |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * @depends testAuthRegister |
|
54 | - * Register User2 |
|
55 | - */ |
|
53 | + * @depends testAuthRegister |
|
54 | + * Register User2 |
|
55 | + */ |
|
56 | 56 | public function testAuthRegister2() |
57 | 57 | { |
58 | 58 | $output = $this->obRegister->authRegister( |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | - * @depends testAuthRegister2 |
|
81 | - * Testing for the register with empty username |
|
82 | - */ |
|
80 | + * @depends testAuthRegister2 |
|
81 | + * Testing for the register with empty username |
|
82 | + */ |
|
83 | 83 | public function testCompose() |
84 | 84 | { |
85 | 85 | $expectedOutput = ['location' => 'http://127.0.0.1/openchat/views/account.php']; |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
137 | - * @depends testAuthRegister2 |
|
138 | - * Testing for Search Class |
|
139 | - */ |
|
137 | + * @depends testAuthRegister2 |
|
138 | + * Testing for Search Class |
|
139 | + */ |
|
140 | 140 | public function testSearch($userId) |
141 | 141 | { |
142 | 142 | $expectedOutput = ['location' => 'http://127.0.0.1/openchat/views/account.php']; |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | |
179 | 179 | |
180 | 180 | /** |
181 | - * @depends testAuthRegister2 |
|
182 | - * Testing for Reply Class |
|
183 | - */ |
|
181 | + * @depends testAuthRegister2 |
|
182 | + * Testing for Reply Class |
|
183 | + */ |
|
184 | 184 | public function testReply($userId) |
185 | 185 | { |
186 | 186 | $expectedOutput = ['location' => 'http://127.0.0.1/openchat/views/account.php']; |
@@ -236,9 +236,9 @@ discard block |
||
236 | 236 | |
237 | 237 | |
238 | 238 | /** |
239 | - * @depends testReply |
|
240 | - * Testing for Search Class |
|
241 | - */ |
|
239 | + * @depends testReply |
|
240 | + * Testing for Search Class |
|
241 | + */ |
|
242 | 242 | public function testSearchWithTotalMessages() |
243 | 243 | { |
244 | 244 | $expectedOutput = ['location' => 'http://127.0.0.1/openchat/views/account.php']; |
@@ -264,8 +264,8 @@ discard block |
||
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
267 | - * Testing for Search Class |
|
268 | - */ |
|
267 | + * Testing for Search Class |
|
268 | + */ |
|
269 | 269 | public function testSidebar() |
270 | 270 | { |
271 | 271 | $expectedOutput = ['location' => 'http://127.0.0.1/openchat/views/account.php']; |
@@ -294,9 +294,9 @@ discard block |
||
294 | 294 | |
295 | 295 | |
296 | 296 | /** |
297 | - * @depends testSidebar |
|
298 | - * Empty the DB |
|
299 | - */ |
|
297 | + * @depends testSidebar |
|
298 | + * Empty the DB |
|
299 | + */ |
|
300 | 300 | public function test_EmptyDB() |
301 | 301 | { |
302 | 302 | $connect = mysqli_connect( |
@@ -9,7 +9,6 @@ |
||
9 | 9 | use ChatApp\Reply; |
10 | 10 | use ChatApp\Session; |
11 | 11 | use ChatApp\SideBar; |
12 | - |
|
13 | 12 | use Dotenv\Dotenv; |
14 | 13 | $dotenv = new Dotenv(dirname(__DIR__)); |
15 | 14 | $dotenv->load(); |
@@ -190,12 +190,12 @@ discard block |
||
190 | 190 | "passLogin" => 'testing' |
191 | 191 | ] |
192 | 192 | ); |
193 | - $outputEmail = (array) json_decode($outputEmail); |
|
193 | + $outputEmail = (array)json_decode($outputEmail); |
|
194 | 194 | $this->assertEquals($expectedOutput, $outputEmail); |
195 | 195 | $currentId = Session::get('start'); |
196 | 196 | Session::forget('start'); |
197 | 197 | |
198 | - $msg =(object) [ |
|
198 | + $msg = (object)[ |
|
199 | 199 | "name" => $userId, |
200 | 200 | "reply" => "Hello World", |
201 | 201 | "userId" => $currentId |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | $output = $obReply->replyTo($msg); |
206 | 206 | $this->assertEquals("Messages is sent", $output); |
207 | 207 | |
208 | - $msg =(object) [ |
|
208 | + $msg = (object)[ |
|
209 | 209 | "name" => $currentId, |
210 | 210 | "reply" => "Hello World", |
211 | 211 | "userId" => $userId |
@@ -218,14 +218,14 @@ discard block |
||
218 | 218 | $output = $obReply->replyTo([]); |
219 | 219 | $this->assertEquals("Failed", $output); |
220 | 220 | |
221 | - $output = $obReply->replyTo((object) [ |
|
221 | + $output = $obReply->replyTo((object)[ |
|
222 | 222 | "name" => -1, |
223 | 223 | "reply" => "Hello World", |
224 | 224 | "userId" => $currentId |
225 | 225 | ]); |
226 | 226 | $this->assertEquals("Invalid Authentication", $output); |
227 | 227 | |
228 | - $output = $obReply->replyTo((object) [ |
|
228 | + $output = $obReply->replyTo((object)[ |
|
229 | 229 | "name" => $userId, |
230 | 230 | "reply" => "Hello", |
231 | 231 | "userId" => $currentId |
@@ -33,18 +33,18 @@ |
||
33 | 33 | if($para == True) |
34 | 34 | { |
35 | 35 | $this->query = "SELECT * from login where login_id = '$details'"; |
36 | - } |
|
37 | - else |
|
36 | + } else |
|
38 | 37 | { |
39 | 38 | $this->query = "SELECT * from login where username = '$details'"; |
40 | 39 | } |
41 | 40 | $this->result = $this->connect->query($this->query); |
42 | - if($this->result->num_rows > 0) // if true |
|
41 | + if($this->result->num_rows > 0) { |
|
42 | + // if true |
|
43 | 43 | { |
44 | 44 | $this->details = $this->result->fetch_assoc(); |
45 | - return $this->details; |
|
46 | 45 | } |
47 | - else |
|
46 | + return $this->details; |
|
47 | + } else |
|
48 | 48 | { |
49 | 49 | return NULL; |
50 | 50 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | |
4 | 4 | namespace ChatApp; |
5 | -require_once (dirname(__DIR__) . '/vendor/autoload.php'); |
|
5 | +require_once (dirname(__DIR__).'/vendor/autoload.php'); |
|
6 | 6 | use Dotenv\Dotenv; |
7 | 7 | $dotenv = new Dotenv(dirname(__DIR__)); |
8 | 8 | $dotenv->load(); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | public function userDetails($details, $para) |
32 | 32 | { |
33 | - if($para == True) |
|
33 | + if ($para == True) |
|
34 | 34 | { |
35 | 35 | $this->query = "SELECT * from login where login_id = '$details'"; |
36 | 36 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | $this->query = "SELECT * from login where username = '$details'"; |
40 | 40 | } |
41 | 41 | $this->result = $this->connect->query($this->query); |
42 | - if($this->result->num_rows > 0) // if true |
|
42 | + if ($this->result->num_rows > 0) // if true |
|
43 | 43 | { |
44 | 44 | $this->details = $this->result->fetch_assoc(); |
45 | 45 | return $this->details; |