Completed
Push — master ( 291cbd...6aab68 )
by Adeniyi
09:08 queued 06:09
created
api/Controllers/AuthController.php 3 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -11,10 +11,8 @@
 block discarded – undo
11 11
 namespace Ibonly\NaijaEmoji;
12 12
 
13 13
 use Exception;
14
-use Slim\Slim;
15 14
 use Dotenv\Dotenv;
16 15
 use Firebase\JWT\JWT;
17
-use Ibonly\NaijaEmoji\User;
18 16
 use Ibonly\NaijaEmoji\AuthInterface;
19 17
 use Ibonly\NaijaEmoji\InvalidTokenException;
20 18
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
     protected $auth_url;
26 26
     protected $issued_by;
27 27
 
28
-    public function __construct ()
28
+    public function __construct()
29 29
     {
30 30
         $this->loadEnv();
31 31
         $this->key        = getenv('ISSUE_KEY');
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      *
39 39
      * @return string
40 40
      */
41
-    public function getKey ()
41
+    public function getKey()
42 42
     {
43 43
         return $this->key;
44 44
     }
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
      *
71 71
      * @return string
72 72
      */
73
-    public function authorizationEncode ($userID)
73
+    public function authorizationEncode($userID)
74 74
     {
75
-        if ( ! is_null($userID) )
75
+        if (!is_null($userID))
76 76
             $token = array(
77 77
                 "iss" => $this->getIssuedBy(),
78 78
                 "aud" => $this->getAuthUrl(),
@@ -89,20 +89,20 @@  discard block
 block discarded – undo
89 89
      *
90 90
      * @return json
91 91
      */
92
-    public function authorizationDecode ($token)
92
+    public function authorizationDecode($token)
93 93
     {
94 94
         try
95 95
         {
96 96
             return JWT::decode($token, $this->getKey(), array('HS256'));
97
-        } catch ( Exception $e) {
97
+        } catch (Exception $e) {
98 98
             throw new InvalidTokenException();
99 99
         }
100 100
 
101 101
     }
102 102
 
103
-    protected function loadEnv ()
103
+    protected function loadEnv()
104 104
     {
105
-        if( ! getenv("APP_ENV" !== "production"))
105
+        if (!getenv("APP_ENV" !== "production"))
106 106
         {
107 107
             $dotenv = new Dotenv($_SERVER['DOCUMENT_ROOT']);
108 108
             $dotenv->load();
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -72,13 +72,14 @@
 block discarded – undo
72 72
      */
73 73
     public function authorizationEncode ($userID)
74 74
     {
75
-        if ( ! is_null($userID) )
76
-            $token = array(
75
+        if ( ! is_null($userID) ) {
76
+                    $token = array(
77 77
                 "iss" => $this->getIssuedBy(),
78 78
                 "aud" => $this->getAuthUrl(),
79 79
                 "user" => $userID,
80 80
                 "exp" => time() + 3600
81 81
             );
82
+        }
82 83
             return JWT::encode($token, $this->getKey());
83 84
     }
84 85
 
Please login to merge, or discard this patch.
api/Controllers/EmojiController.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      *
38 38
      * @param  $app
39 39
      *
40
-     * @return json
40
+     * @return string|null
41 41
      */
42 42
     public function getAllEmoji (Slim $app)
43 43
     {
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      * @param  $id
62 62
      * @param  $app
63 63
      *
64
-     * @return json
64
+     * @return string|null
65 65
      */
66 66
     public function findEmoji ($id, Slim $app)
67 67
     {
Please login to merge, or discard this patch.
Braces   +18 added lines, -12 removed lines patch added patch discarded remove patch
@@ -92,8 +92,9 @@  discard block
 block discarded – undo
92 92
         $tokenData = $app->request->headers->get('Authorization');
93 93
         try
94 94
         {
95
-            if ( ! isset( $tokenData ) )
96
-                throw new ProvideTokenException();
95
+            if ( ! isset( $tokenData ) ) {
96
+                            throw new ProvideTokenException();
97
+            }
97 98
 
98 99
             $data = $this->auth->authorizationDecode($tokenData);
99 100
             $this->dataName->id = NULL;
@@ -106,8 +107,9 @@  discard block
 block discarded – undo
106 107
             $this->dataName->created_by = $data->user;
107 108
 
108 109
             $save = $this->dataName->save();
109
-            if ( $save )
110
-                $app->halt(200, json_encode(['Message' => 'Success']));
110
+            if ( $save ) {
111
+                            $app->halt(200, json_encode(['Message' => 'Success']));
112
+            }
111 113
         } catch ( ExpiredException $e ){
112 114
             $app->halt(401, json_encode(['Message' => 'Not Authorized']));
113 115
         } catch ( SaveUserExistException $e ){
@@ -133,8 +135,9 @@  discard block
 block discarded – undo
133 135
         $tokenData = $app->request->headers->get('Authorization');
134 136
         try
135 137
         {
136
-            if ( ! isset($tokenData) )
137
-                throw new ProvideTokenException();
138
+            if ( ! isset($tokenData) ) {
139
+                            throw new ProvideTokenException();
140
+            }
138 141
 
139 142
             $find = Emoji::find($id);
140 143
             $this->auth->authorizationDecode($tokenData);
@@ -145,8 +148,9 @@  discard block
 block discarded – undo
145 148
             }
146 149
             $find->date_modified = date('Y-m-d G:i:s');
147 150
             $update = $find->update();
148
-            if( $update )
149
-                $app->halt(200, json_encode(['Message' => 'Emoji Updated Successfully']));
151
+            if( $update ) {
152
+                            $app->halt(200, json_encode(['Message' => 'Emoji Updated Successfully']));
153
+            }
150 154
         } catch ( ExpiredException $e ){
151 155
             $app->halt(401, json_encode(['Message' => 'Not Authorized']));
152 156
         } catch ( SaveUserExistException $e ){
@@ -174,13 +178,15 @@  discard block
 block discarded – undo
174 178
         $tokenData = $app->request->headers->get('Authorization');
175 179
         try
176 180
         {
177
-            if ( ! isset($tokenData) )
178
-                throw new ProvideTokenException();
181
+            if ( ! isset($tokenData) ) {
182
+                            throw new ProvideTokenException();
183
+            }
179 184
 
180 185
             $this->auth->authorizationDecode($tokenData);
181 186
             $deleted = $this->dataName->destroy($id);
182
-            if ( $deleted )
183
-                $app->halt(200, json_encode(['Message' => 'Emoji Deleted']));
187
+            if ( $deleted ) {
188
+                            $app->halt(200, json_encode(['Message' => 'Emoji Deleted']));
189
+            }
184 190
         } catch ( ExpiredException $e ){
185 191
             $app->halt(401, json_encode(['Message' => 'Not Authorized']));
186 192
         } catch ( InvalidTokenException $e ){
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
     protected $dataName;
28 28
     protected $auth;
29 29
 
30
-    public function __construct ()
30
+    public function __construct()
31 31
     {
32 32
         $this->dataName = new Emoji();
33 33
         $this->auth = new AuthController();
@@ -40,18 +40,18 @@  discard block
 block discarded – undo
40 40
      *
41 41
      * @return json
42 42
      */
43
-    public function getAllEmoji (Slim $app)
43
+    public function getAllEmoji(Slim $app)
44 44
     {
45 45
         $app->response->headers->set('Content-Type', 'application/json');
46 46
         try
47 47
         {
48 48
             $data = $this->dataName->getAll()->toJson();
49 49
             $newData = json_decode($data);
50
-            foreach ( $newData as $key ) {
50
+            foreach ($newData as $key) {
51 51
                 $key->keywords = explode(", ", $key->keywords);
52 52
             }
53 53
             return json_encode($newData);
54
-        } catch ( EmptyDatabaseException $e ) {
54
+        } catch (EmptyDatabaseException $e) {
55 55
             $app->halt(204, json_encode(['Message' => 'No content']));
56 56
         }
57 57
     }
@@ -64,18 +64,18 @@  discard block
 block discarded – undo
64 64
      *
65 65
      * @return json
66 66
      */
67
-    public function findEmoji ($id, Slim $app)
67
+    public function findEmoji($id, Slim $app)
68 68
     {
69 69
         $app->response->headers->set('Content-Type', 'application/json');
70 70
         try
71 71
         {
72
-            $data =  $this->dataName->where(['id' => $id])->toJson();
72
+            $data = $this->dataName->where(['id' => $id])->toJson();
73 73
             $newData = json_decode($data);
74
-            foreach ( $newData as $key ) {
74
+            foreach ($newData as $key) {
75 75
                 $key->keywords = explode(", ", $key->keywords);
76 76
             }
77 77
             return json_encode($newData);
78
-        } catch ( DataNotFoundException $e ) {
78
+        } catch (DataNotFoundException $e) {
79 79
             $app->halt(404, json_encode(['Message' => 'Not Found']));
80 80
         }
81 81
     }
@@ -87,13 +87,13 @@  discard block
 block discarded – undo
87 87
      *
88 88
      * @return json
89 89
      */
90
-    public function insertEmoji (Slim $app)
90
+    public function insertEmoji(Slim $app)
91 91
     {
92 92
         $app->response->headers->set('Content-Type', 'application/json');
93 93
         $tokenData = $app->request->headers->get('Authorization');
94 94
         try
95 95
         {
96
-            if ( ! isset( $tokenData ) )
96
+            if (!isset($tokenData))
97 97
                 throw new ProvideTokenException();
98 98
 
99 99
             $data = $this->auth->authorizationDecode($tokenData);
@@ -107,15 +107,15 @@  discard block
 block discarded – undo
107 107
             $this->dataName->created_by = $data->user;
108 108
 
109 109
             $save = $this->dataName->save();
110
-            if ( $save )
110
+            if ($save)
111 111
                 $app->halt(200, json_encode(['Message' => 'Success']));
112
-        } catch ( ExpiredException $e ){
112
+        } catch (ExpiredException $e) {
113 113
             $app->halt(401, json_encode(['Message' => 'Token has expired']));
114
-        } catch ( DataAlreadyExistException $e ){
114
+        } catch (DataAlreadyExistException $e) {
115 115
             $app->halt(202, json_encode(['Message' => 'Not Created']));
116
-        } catch ( InvalidTokenException $e ){
116
+        } catch (InvalidTokenException $e) {
117 117
             $app->halt(405, json_encode(['Message' => 'Invalid Token']));
118
-        } catch ( ProvideTokenException $e ){
118
+        } catch (ProvideTokenException $e) {
119 119
             $app->halt(406, json_encode(['Message' => 'Enter a valid Token']));
120 120
         }
121 121
     }
@@ -128,35 +128,35 @@  discard block
 block discarded – undo
128 128
      *
129 129
      * @return json
130 130
      */
131
-    public function updateEmoji ($id, Slim $app)
131
+    public function updateEmoji($id, Slim $app)
132 132
     {
133 133
         $app->response->headers->set('Content-Type', 'application/json');
134 134
         $tokenData = $app->request->headers->get('Authorization');
135 135
         try
136 136
         {
137
-            if ( ! isset($tokenData) )
137
+            if (!isset($tokenData))
138 138
                 throw new ProvideTokenException();
139 139
 
140 140
             $find = Emoji::find($id);
141 141
             $this->auth->authorizationDecode($tokenData);
142 142
             $fields = $app->request->isPut() ? $app->request->put() : $app->request->patch();
143
-            foreach ( $fields as $key => $value )
143
+            foreach ($fields as $key => $value)
144 144
             {
145 145
                 $find->$key = $value;
146 146
             }
147 147
             $find->date_modified = date('Y-m-d G:i:s');
148 148
             $update = $find->update();
149
-            if( $update )
149
+            if ($update)
150 150
                 $app->halt(200, json_encode(['Message' => 'Emoji Updated Successfully']));
151
-        } catch ( ExpiredException $e ){
151
+        } catch (ExpiredException $e) {
152 152
             $app->halt(401, json_encode(['Message' => 'Token has expired']));
153
-        } catch ( DataAlreadyExistException $e ){
153
+        } catch (DataAlreadyExistException $e) {
154 154
             $app->halt(304, json_encode(['Message' => 'Not Modified']));
155
-        } catch ( DataNotFoundException $e ){
155
+        } catch (DataNotFoundException $e) {
156 156
             $app->halt(304, json_encode(['Message' => 'Invalid Credential supplied']));
157
-        } catch ( InvalidTokenException $e ){
157
+        } catch (InvalidTokenException $e) {
158 158
             $app->halt(405, json_encode(['Message' => 'Invalid Token']));
159
-        } catch ( ProvideTokenException $e ){
159
+        } catch (ProvideTokenException $e) {
160 160
             $app->halt(406, json_encode(['Message' => 'Enter a valid Token']));
161 161
         }
162 162
     }
@@ -169,24 +169,24 @@  discard block
 block discarded – undo
169 169
      *
170 170
      * @return json
171 171
      */
172
-    public function deleteEmoji ($id, Slim $app)
172
+    public function deleteEmoji($id, Slim $app)
173 173
     {
174 174
         $app->response->headers->set('Content-Type', 'application/json');
175 175
         $tokenData = $app->request->headers->get('Authorization');
176 176
         try
177 177
         {
178
-            if ( ! isset($tokenData) )
178
+            if (!isset($tokenData))
179 179
                 throw new ProvideTokenException();
180 180
 
181 181
             $this->auth->authorizationDecode($tokenData);
182 182
             $deleted = $this->dataName->destroy($id);
183
-            if ( $deleted )
183
+            if ($deleted)
184 184
                 $app->halt(200, json_encode(['Message' => 'Emoji Deleted']));
185
-        } catch ( ExpiredException $e ){
185
+        } catch (ExpiredException $e) {
186 186
             $app->halt(401, json_encode(['Message' => 'Token has expired']));
187
-        } catch ( InvalidTokenException $e ){
187
+        } catch (InvalidTokenException $e) {
188 188
             $app->halt(405, json_encode(['Message' => 'Invalid Token']));
189
-        } catch ( ProvideTokenException $e ){
189
+        } catch (ProvideTokenException $e) {
190 190
             $app->halt(406, json_encode(['Message' => 'Enter a valid Token']));
191 191
         }
192 192
     }
Please login to merge, or discard this patch.
api/Controllers/UserController.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@
 block discarded – undo
56 56
      *
57 57
      * @param  $app
58 58
      *
59
-     * @return json
59
+     * @return string|null
60 60
      */
61 61
     public function login (Slim $app)
62 62
     {
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -94,8 +94,9 @@
 block discarded – undo
94 94
         $tokenData = $app->request->headers->get('Authorization');
95 95
         try
96 96
         {
97
-            if ( ! isset( $tokenData ) )
98
-                throw new ProvideTokenException();
97
+            if ( ! isset( $tokenData ) ) {
98
+                            throw new ProvideTokenException();
99
+            }
99 100
 
100 101
             $checkUser = $this->user->where(['username' => $tokenData->user])->all();
101 102
             if( ! empty ($checkUser) ){
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      *
37 37
      * @return json
38 38
      */
39
-    public function createUser (Slim $app)
39
+    public function createUser(Slim $app)
40 40
     {
41 41
         $username = $app->request->params('username');
42 42
         $this->user->id = NULL;
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
         $this->user->date_created = date('Y-m-d H:i:s');
46 46
 
47 47
         $save = $this->user->save();
48
-        if( $save )
48
+        if ($save)
49 49
         {
50 50
             $app->halt(201, json_encode(['message' => 'Registration Successful. Please Login to generate your token']));
51 51
         }
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      *
59 59
      * @return json
60 60
      */
61
-    public function login (Slim $app)
61
+    public function login(Slim $app)
62 62
     {
63 63
         $app->response->headers->set('Content-Type', 'application/json');
64 64
         $username = $app->request->params('username');
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
         try
67 67
         {
68 68
             $login = $this->user->where(['username' => $username, 'password' => md5($password)], 'AND')->toJson();
69
-            if( ! empty ($login) ){
69
+            if (!empty ($login)) {
70 70
                 $output = json_decode($login);
71 71
                 foreach ($output as $key) {
72 72
                     $output = $key->id;
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
                     'Authorization' => $this->auth->authorizationEncode($username)
77 77
                 ]));
78 78
             }
79
-        } catch ( DataNotFoundException $e) {
79
+        } catch (DataNotFoundException $e) {
80 80
             $app->halt(404, json_encode(['message' => 'Not Found']));
81 81
         }
82 82
     }
@@ -88,25 +88,25 @@  discard block
 block discarded – undo
88 88
      *
89 89
      * @return json
90 90
      */
91
-    public function logout (Slim $app)
91
+    public function logout(Slim $app)
92 92
     {
93 93
         $app->response->headers->set('Content-Type', 'application/json');
94 94
         $tokenData = $app->request->headers->get('Authorization');
95 95
         try
96 96
         {
97
-            if ( ! isset( $tokenData ) )
97
+            if (!isset($tokenData))
98 98
                 throw new ProvideTokenException();
99 99
 
100 100
             $checkUser = $this->user->where(['username' => $tokenData->user])->toJson();
101
-            if( ! empty ($checkUser) ){
102
-                $this->auth->authorizationEncode(NULL);#
101
+            if (!empty ($checkUser)) {
102
+                $this->auth->authorizationEncode(NULL); #
103 103
                 $app->halt(200, json_encode(['message' => 'Logged out Successfully']));
104 104
             }
105
-        } catch ( DataNotFoundException $e) {
105
+        } catch (DataNotFoundException $e) {
106 106
             $app->halt(404, json_encode(['message' => 'Not Found']));
107
-        } catch ( InvalidTokenException $e ){
107
+        } catch (InvalidTokenException $e) {
108 108
             $app->halt(405, json_encode(['Message' => 'Invalid Token']));
109
-        } catch ( ProvideTokenException $e ){
109
+        } catch (ProvideTokenException $e) {
110 110
             $app->halt(406, json_encode(['Message' => 'Enter a valid Token']));
111 111
         }
112 112
     }
Please login to merge, or discard this patch.
api/Interface/AuthInterface.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@
 block discarded – undo
12 12
 
13 13
 interface AuthInterface
14 14
 {
15
-    public function getKey ();
15
+    public function getKey();
16 16
 
17 17
     public function getIssuedBy();
18 18
 
19 19
     public function getAuthUrl();
20 20
 
21
-    public function authorizationEncode ($username);
21
+    public function authorizationEncode($username);
22 22
 
23
-    public function authorizationDecode ($token);
23
+    public function authorizationDecode($token);
24 24
 
25 25
 }
26 26
\ No newline at end of file
Please login to merge, or discard this patch.
api/Interface/EmojiInterface.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,13 +14,13 @@
 block discarded – undo
14 14
 
15 15
 interface EmojiInterface
16 16
 {
17
-    public function getAllEmoji (Slim $app);
17
+    public function getAllEmoji(Slim $app);
18 18
 
19
-    public function findEmoji ($id, Slim $app);
19
+    public function findEmoji($id, Slim $app);
20 20
 
21
-    public function insertEmoji (Slim $app);
21
+    public function insertEmoji(Slim $app);
22 22
 
23
-    public function updateEmoji ($id, Slim $app);
23
+    public function updateEmoji($id, Slim $app);
24 24
 
25
-    public function deleteEmoji ($id, Slim $app);
25
+    public function deleteEmoji($id, Slim $app);
26 26
 }
27 27
\ No newline at end of file
Please login to merge, or discard this patch.
api/Interface/UserInterface.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -15,9 +15,9 @@
 block discarded – undo
15 15
 interface UserInterface
16 16
 {
17 17
 
18
-    public function createUser (Slim $app);
18
+    public function createUser(Slim $app);
19 19
 
20
-    public function login (Slim $app);
20
+    public function login(Slim $app);
21 21
 
22
-    public function logout (Slim $app);
22
+    public function logout(Slim $app);
23 23
 }
24 24
\ No newline at end of file
Please login to merge, or discard this patch.
index.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,11 +14,11 @@  discard block
 block discarded – undo
14 14
 /**
15 15
  * Emoji Route
16 16
  */
17
-$app->get('/emojis', function () use ($emoji, $app) {
17
+$app->get('/emojis', function() use ($emoji, $app) {
18 18
     echo $emoji->getAllEmoji($app);
19 19
 });
20 20
 
21
-$app->get('/emojis/:id', function ($id) use ($emoji, $app) {
21
+$app->get('/emojis/:id', function($id) use ($emoji, $app) {
22 22
     echo $emoji->findEmoji($id, $app);
23 23
 });
24 24
 
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
 /**
42 42
  * User Route
43 43
  */
44
-$app->post('/register', function () use ($user, $app) {
44
+$app->post('/register', function() use ($user, $app) {
45 45
     echo $user->createUser($app);
46 46
 });
47 47
 
48
-$app->post('/auth/login', function () use ($user, $app) {
48
+$app->post('/auth/login', function() use ($user, $app) {
49 49
     echo $user->login($app);
50 50
 });
51
-$app->get('/auth/logout', function () use ($user, $app) {
51
+$app->get('/auth/logout', function() use ($user, $app) {
52 52
     echo $user->logout($app);
53 53
 });
54 54
 
Please login to merge, or discard this patch.
d.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@
 block discarded – undo
8 8
 
9 9
 $request = $client->get('/emojis');
10 10
 // $request->setAuth('user', 'pass');
11
-echo $request->getUrl()."<br />";
11
+echo $request->getUrl() . "<br />";
12 12
 // >>> https://api.github.com/user
13 13
 
14 14
 // You must send a request in order for the transfer to occur
15 15
 $response = $request->send();
16 16
 
17
-echo $response->getBody()."<br />";
17
+echo $response->getBody() . "<br />";
18 18
 // >>> {"type":"User", ...
19 19
 
20
-echo $response->getHeader('Content-Length')."<br />";
20
+echo $response->getHeader('Content-Length') . "<br />";
21 21
 // >>> 792
22 22
 
23 23
 $data = $response->json();
Please login to merge, or discard this patch.
test/RoutesTest.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
     /**
45 45
      * Test Post endpoint
46 46
      */
47
-   public function testPOSTEmoji()
47
+    public function testPOSTEmoji()
48 48
     {
49 49
         // create our http client (Guzzle)
50 50
         $data = array(
Please login to merge, or discard this patch.