Completed
Push — master ( d60caa...394d07 )
by Ankit
02:48
created
views/validate_login.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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([]);
Please login to merge, or discard this patch.
views/message.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 ?>
Please login to merge, or discard this patch.
src/Session.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -10,6 +10,9 @@
 block discarded – undo
10 10
         $_SESSION[$key] = $value;
11 11
     }
12 12
 
13
+    /**
14
+     * @param string $key
15
+     */
13 16
     public static function get($key){
14 17
         return (isset($_SESSION[$key]) ? $_SESSION[$key] : null);
15 18
     }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -6,15 +6,15 @@
 block discarded – undo
6 6
 class Session
7 7
 {
8 8
 
9
-    public static function put($key, $value){
9
+    public static function put($key, $value) {
10 10
         $_SESSION[$key] = $value;
11 11
     }
12 12
 
13
-    public static function get($key){
13
+    public static function get($key) {
14 14
         return (isset($_SESSION[$key]) ? $_SESSION[$key] : null);
15 15
     }
16 16
 
17
-    public static function forget($key){
17
+    public static function forget($key) {
18 18
         unset($_SESSION[$key]);
19 19
     }
20 20
 
Please login to merge, or discard this patch.
index.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once (__DIR__ . '/vendor/autoload.php');
3
+require_once (__DIR__.'/vendor/autoload.php');
4 4
 use ChatApp\Session;
5 5
 use Dotenv\Dotenv;
6 6
 $dotenv = new Dotenv(__DIR__);
7 7
 $dotenv->load();
8 8
 
9 9
 // die("Hello");
10
-if(Session::get('start') != null)
10
+if (Session::get('start') != null)
11 11
 {
12 12
     header("Location:".getenv('APP_URL')."/views/account.php");
13 13
 }
Please login to merge, or discard this patch.
views/validate_register.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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([]);
Please login to merge, or discard this patch.
tests/TestAll.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -190,12 +190,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
src/Chat.php 2 patches
Doc Comments   +11 added lines patch added patch discarded remove patch
@@ -25,6 +25,9 @@  discard block
 block discarded – undo
25 25
         Online::setOnlineStatus($conn->userId);
26 26
     }
27 27
 
28
+    /**
29
+     * @param ConnectionInterface $conn
30
+     */
28 31
     public function setID($conn) {
29 32
         session_id($conn->WebSocket->request->getCookies()['PHPSESSID']);
30 33
         @session_start();
@@ -117,11 +120,19 @@  discard block
 block discarded – undo
117 120
         return $obSidebar->loadSideBar($data);
118 121
     }
119 122
 
123
+    /**
124
+     * @param string $data
125
+     * @param boolean $para
126
+     */
120 127
     public function onConversation($data, $para) {
121 128
         $obConversation = new Conversation();
122 129
         return $obConversation->conversationLoad($data, $para);
123 130
     }
124 131
 
132
+    /**
133
+     * @param string $data
134
+     * @param boolean $para
135
+     */
125 136
     public function onReceiver($data, $para) {
126 137
         $obReceiver = new Receiver();
127 138
         return $obReceiver->receiverLoad($data, $para);
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
     }
35 35
 
36 36
     public function onMessage(ConnectionInterface $from, $msg) {
37
-        $msg = (object) json_decode($msg);
37
+        $msg = (object)json_decode($msg);
38 38
         if ($msg->type == 'OpenChat initiated..!') {
39
-            $initial = (object) array();
39
+            $initial = (object)array();
40 40
             $initial->initial = json_decode($this->onSidebar($from->userId));
41 41
 
42 42
             if ($initial->initial != null) {
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
             }
53 53
             $from->send(json_encode($initial));
54 54
         } else if ($msg->type == 'Load Sidebar') {
55
-            $sidebar = (object) array();
55
+            $sidebar = (object)array();
56 56
             $sidebar->sidebar = json_decode($this->onSidebar($from->userId));
57 57
             $from->send(json_encode($sidebar));
58 58
         } else if ($msg->type == 'Initiated') {
59 59
             $msg->userId = $from->userId;
60
-            $result = (object) array();
60
+            $result = (object)array();
61 61
             $result->conversation = json_decode($this->onConversation(json_encode($msg), False));
62 62
             $from->send(json_encode($result));
63 63
         } else if ($msg->type == 'Search') {
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
             $getReturn = $this->onReply($msg);
76 76
             echo $getReturn;
77 77
 
78
-            $receiveResult = (object) array();
79
-            $sentResult = (object) array();
78
+            $receiveResult = (object)array();
79
+            $sentResult = (object)array();
80 80
             foreach ($this->clients as $client)
81 81
             {
82 82
                 if ($client->userId == $msg->name) {
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
                     );
94 94
 
95 95
                     $client->send(json_encode($receiveResult));
96
-                } else if($client == $from) {
96
+                } else if ($client == $from) {
97 97
                     $sentResult->sidebar = json_decode($this->onSidebar($client->userId));
98 98
 
99 99
                     $sentResult->conversation = json_decode(
Please login to merge, or discard this patch.
src/Register.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -94,6 +94,9 @@
 block discarded – undo
94 94
     }
95 95
 
96 96
 
97
+    /**
98
+     * @param string $value
99
+     */
97 100
     public function onError($key, $value)
98 101
     {
99 102
         $this->flag = 1;
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -76,12 +76,12 @@
 block discarded – undo
76 76
             $query = "INSERT INTO login VALUES('$userId', '$name', '$email', '$username', '$mob', 0)";
77 77
 
78 78
             if (!$this->connect->query($query)) {
79
-                return json_encode(["Error" => "You are not registered, ".$this->connect->error ]);
79
+                return json_encode(["Error" => "You are not registered, ".$this->connect->error]);
80 80
             }
81 81
 
82 82
             $query = "INSERT INTO profile VALUES('$userId', 'Joined OpenChat', 'Joined OpenChat', '')";
83 83
             if (!$this->connect->query($query)) {
84
-                return json_encode(["Error" => "You are not registered, ".$this->connect->error ]);
84
+                return json_encode(["Error" => "You are not registered, ".$this->connect->error]);
85 85
             }
86 86
 
87 87
             Session::put('start', $userId);
Please login to merge, or discard this patch.
src/Reply.php 2 patches
Doc Comments   +5 added lines patch added patch discarded remove patch
@@ -75,6 +75,11 @@
 block discarded – undo
75 75
         return "Failed";
76 76
     }
77 77
 
78
+    /**
79
+     * @param string $identifier
80
+     * @param string $reply
81
+     * @param string $time
82
+     */
78 83
     public function updateMessages($query, $identifier, $reply, $userId, $time)
79 84
     {
80 85
         if ($result = $this->connect->query($query)) {
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -36,16 +36,16 @@  discard block
 block discarded – undo
36 36
                 // geneate specific unique code to store messages
37 37
                 $user1 = $userId;
38 38
                 $user2 = $receiverID;
39
-                $identifier = $userId . ":" . $receiverID;
39
+                $identifier = $userId.":".$receiverID;
40 40
             } else {
41 41
                 $user1 = $receiverID;
42 42
                 $user2 = $userId;
43
-                $identifier = $receiverID . ":" . $userId;
43
+                $identifier = $receiverID.":".$userId;
44 44
             }
45 45
 
46 46
             $reply = addslashes(trim($msg->reply)); // stores the message sent by the user.
47 47
 
48
-            $time = date("D d M Y H:i:s", time() + 16200);  // current time
48
+            $time = date("D d M Y H:i:s", time() + 16200); // current time
49 49
             $time_id = date("YmdHis", time() + 16200); //to sort the array on the basis of time
50 50
 
51 51
             //the sender id must not be equal to current session id
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
                         return $this->updateMessages($query, $identifier, $reply, $userId, $time);
70 70
                     }
71 71
                 }
72
-                return "Invalid Authentication";  // if he is unauthorized echo message is failed
72
+                return "Invalid Authentication"; // if he is unauthorized echo message is failed
73 73
             }
74 74
         }
75 75
         return "Failed";
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
             //insert message in db
82 82
             $query = "INSERT into messages values('$identifier', '$reply', '$userId', '$time', null)";
83 83
             if ($this->connect->query($query)) {
84
-                return "Messages is sent";    // if query is executed return true
84
+                return "Messages is sent"; // if query is executed return true
85 85
             }
86 86
             return "Message is failed";
87 87
         }
Please login to merge, or discard this patch.