Passed
Push — develop ( 319bd8...330c7a )
by Neill
16:41 queued 15s
created
neon/user/grid/UserGrid.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -45,10 +45,10 @@  discard block
 block discarded – undo
45 45
 			$this->addTextColumn('impersonate')->setFilter(false);
46 46
 		// scopes
47 47
 		// $this->addScope('all','All');
48
-		$this->addScope('active','Active');
49
-		$this->addScope('pending','Pending');
50
-		$this->addScope('suspended','Suspended');
51
-		$this->addScope('banned','Banned');
48
+		$this->addScope('active', 'Active');
49
+		$this->addScope('pending', 'Pending');
50
+		$this->addScope('suspended', 'Suspended');
51
+		$this->addScope('banned', 'Banned');
52 52
 		$this->addScope('super', 'Super');
53 53
 
54 54
 		$this->setPageSize(100);
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	 */
197 197
 	private function getRoles()
198 198
 	{
199
-		static $roles=null;
199
+		static $roles = null;
200 200
 		if (is_null($roles)) {
201 201
 			$roles = neon('user')->getRoles(true);
202 202
 		}
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 	 */
211 211
 	private function getRoleLabels()
212 212
 	{
213
-		static $labels=null;
213
+		static $labels = null;
214 214
 		if (is_null($labels)) {
215 215
 			$roles = $this->getRoles();
216 216
 			foreach ($roles as $role => $details)
Please login to merge, or discard this patch.
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -41,8 +41,9 @@  discard block
 block discarded – undo
41 41
 		$this->addTextColumn('created_at');
42 42
 		$this->addTextColumn('updated_at', ['title'=>'Updated At']);
43 43
 		// action
44
-		if (neon()->user->isSuper())
45
-			$this->addTextColumn('impersonate')->setFilter(false);
44
+		if (neon()->user->isSuper()) {
45
+					$this->addTextColumn('impersonate')->setFilter(false);
46
+		}
46 47
 		// scopes
47 48
 		// $this->addScope('all','All');
48 49
 		$this->addScope('active','Active');
@@ -104,8 +105,9 @@  discard block
 block discarded – undo
104 105
 		$userRoles = explode('|', $column->getCellData($model));
105 106
 		$displayRoles = [];
106 107
 		foreach ($userRoles as $ur) {
107
-			if (isset($roles[$ur]))
108
-				$displayRoles[] = $column->highlight($roles[$ur]['label'], $search);
108
+			if (isset($roles[$ur])) {
109
+							$displayRoles[] = $column->highlight($roles[$ur]['label'], $search);
110
+			}
109 111
 		}
110 112
 		return implode(', ', $displayRoles);
111 113
 	}
@@ -213,8 +215,9 @@  discard block
 block discarded – undo
213 215
 		static $labels=null;
214 216
 		if (is_null($labels)) {
215 217
 			$roles = $this->getRoles();
216
-			foreach ($roles as $role => $details)
217
-				$labels[$details['label']] = $role;
218
+			foreach ($roles as $role => $details) {
219
+							$labels[$details['label']] = $role;
220
+			}
218 221
 		}
219 222
 		return $labels;
220 223
 	}
@@ -230,8 +233,9 @@  discard block
 block discarded – undo
230 233
 		$labels = $this->getRoleLabels();
231 234
 		$roles = [];
232 235
 		foreach ($labels as $label => $role) {
233
-			if (stripos($label, $filter) !== false)
234
-				$roles[] = $role;
236
+			if (stripos($label, $filter) !== false) {
237
+							$roles[] = $role;
238
+			}
235 239
 		}
236 240
 		return $roles;
237 241
 	}
Please login to merge, or discard this patch.
neon/user/services/apiTokenManager/JwtTokenAuth.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
 		try {
114 114
 			$jwt = (array) JWT::decode($cookieString, static::secret(), ['HS256']);
115 115
 		} catch (Exception $e) {
116
-			throw new UnauthorizedHttpException('Your request was made with invalid credentials.' . neon()->debug ? ' Can not decode JWT token' : '');
116
+			throw new UnauthorizedHttpException('Your request was made with invalid credentials.'.neon()->debug ? ' Can not decode JWT token' : '');
117 117
 		}
118 118
 		// We will compare the CSRF token in the decoded API token against the CSRF header
119 119
 		// sent with the request. If the two don't match then this request is sent from
120 120
 		// an invalid source and we won't authenticate the request for further handling.
121 121
 		if (!$this->validCsrf($jwt, $request)) {
122
-			throw new UnauthorizedHttpException('Your request was made with invalid credentials.' . neon()->debug ? ' CSRF validation failed' : '');
122
+			throw new UnauthorizedHttpException('Your request was made with invalid credentials.'.neon()->debug ? ' CSRF validation failed' : '');
123 123
 		}
124 124
 
125 125
 		return $jwt;
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	 */
216 216
 	protected static function requestShouldReceiveFreshToken(Request $request)
217 217
 	{
218
-		return $request->isMethod('GET') && neon()->user->isLoggedIn() && ! $request->getIsAjax();
218
+		return $request->isMethod('GET') && neon()->user->isLoggedIn() && !$request->getIsAjax();
219 219
 	}
220 220
 
221 221
 	/**
@@ -227,6 +227,6 @@  discard block
 block discarded – undo
227 227
 	protected static function responseShouldReceiveFreshToken(Response $response)
228 228
 	{
229 229
 		// if the cookie already exists do not create another one
230
-		return ! isset($response->cookies[static::$cookieName]);
230
+		return !isset($response->cookies[static::$cookieName]);
231 231
 	}
232 232
 }
233 233
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -56,8 +56,9 @@  discard block
 block discarded – undo
56 56
 		// As there is no cookie or cookie string we return null allowing other authentication methods
57 57
 		// to attempt authentication
58 58
 		$tokenString = $this->getJwtStringFromCookie($request);
59
-		if ($tokenString === null)
60
-			return null;
59
+		if ($tokenString === null) {
60
+					return null;
61
+		}
61 62
 		// decode the cookie and perform csrf validation
62 63
 		// this only checks that the cookie data is good
63 64
 		$jwt = $this->decodeAndValidateJwtToken($tokenString, $request);
@@ -69,8 +70,9 @@  discard block
 block discarded – undo
69 70
 		// @see self::findAndValidateUserIdentity()
70 71
 		// this is similar to the stock yii classes yii\filters\auth\HttpBearerAuth and yii\filters\auth\QueryParamAuth;
71 72
 		$identity = $user->loginByAccessToken($jwt, get_class($this));
72
-		if ($identity === null)
73
-			$this->handleFailure($response);
73
+		if ($identity === null) {
74
+					$this->handleFailure($response);
75
+		}
74 76
 
75 77
 		return $identity;
76 78
 	}
@@ -132,8 +134,9 @@  discard block
 block discarded – undo
132 134
 	 */
133 135
 	public function getJwtStringFromCookie(Request $request)
134 136
 	{
135
-		if (!$request->cookies->has(static::$cookieName))
136
-			return null;
137
+		if (!$request->cookies->has(static::$cookieName)) {
138
+					return null;
139
+		}
137 140
 		$cookie = $request->cookies->get(static::$cookieName)->value;
138 141
 		return $cookie;
139 142
 	}
Please login to merge, or discard this patch.
neon/user/services/apiTokenManager/models/UserApiToken.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 */
91 91
 	public function getHttpBasicAuthorizationBase64()
92 92
 	{
93
-		return base64_encode($this->user_id . ':' . $this->token);
93
+		return base64_encode($this->user_id.':'.$this->token);
94 94
 	}
95 95
 
96 96
 	/**
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 * @param string $name
111 111
 	 * @return UserApiToken|null
112 112
 	 */
113
-	public static function generateTokenFor($userId, $name='')
113
+	public static function generateTokenFor($userId, $name = '')
114 114
 	{
115 115
 		$token = UserApiToken::getTokenRecord($userId);
116 116
 		// extra security:
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -55,17 +55,20 @@
 block discarded – undo
55 55
 	public static function getValidUserByToken($token)
56 56
 	{
57 57
 		$validToken = self::isValidToken($token);
58
-		if (!$validToken)
59
-			return null;
58
+		if (!$validToken) {
59
+					return null;
60
+		}
60 61
 
61 62
 		$apiToken = self::findOne(['active' => 1, 'token' => (string) $token]);
62
-		if ($apiToken == null)
63
-			return null;
63
+		if ($apiToken == null) {
64
+					return null;
65
+		}
64 66
 
65 67
 		// TODO: SO 27/10/2018 - update this to be User::findIndentity() - migrate to uuids.
66 68
 		$user = User::findOne(['id' => $apiToken->user_id, 'status' => User::STATUS_ACTIVE]);
67
-		if ($user == null)
68
-			return null;
69
+		if ($user == null) {
70
+					return null;
71
+		}
69 72
 
70 73
 		// Usage successful
71 74
 		$apiToken->touchTokenUsed();
Please login to merge, or discard this patch.
neon/user/services/UserManager.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	/**
48 48
 	 * @inheritdoc
49 49
 	 */
50
-	public function listUsers(Iterator &$iterator=null)
50
+	public function listUsers(Iterator &$iterator = null)
51 51
 	{
52 52
 		return $this->findUsers(null, $iterator);
53 53
 	}
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	/**
56 56
 	 * @inheritdoc
57 57
 	 */
58
-	public function searchUsers($searchString, Iterator &$iterator=null)
58
+	public function searchUsers($searchString, Iterator &$iterator = null)
59 59
 	{
60 60
 		return $this->findUsers(['like', 'username', $searchString], $iterator);
61 61
 	}
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	/**
64 64
 	 * @inheritdoc
65 65
 	 */
66
-	public function addUser($username, $email, $password, $roles=[], $superuser=false)
66
+	public function addUser($username, $email, $password, $roles = [], $superuser = false)
67 67
 	{
68 68
 		$user = new UserModel;
69 69
 		$user->uuid = Hash::uuid64();
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 				'uuid'=>$user->uuid,
96 96
 				'username'=>$user->username,
97 97
 				'email'=>$user->email,
98
-				'superuser'=>(boolean)$user->super,
98
+				'superuser'=>(boolean) $user->super,
99 99
 				'status' => $user->status,
100 100
 				'roles'=>$user->getRoles()
101 101
 			];
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	{
114 114
 		$user = $this->findUserModel($uuid);
115 115
 		if ($user) {
116
-			$newValues = array_intersect_key($changes, array_flip(['email','password','roles']));
116
+			$newValues = array_intersect_key($changes, array_flip(['email', 'password', 'roles']));
117 117
 			foreach ($newValues as $key=>$value) {
118 118
 				$user->$key = $value;
119 119
 			}
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 *   for the query.
154 154
 	 * @param Iterator $iterator  an iterator to go over the query
155 155
 	 */
156
-	private function findUsers($where, Iterator &$iterator=null) 
156
+	private function findUsers($where, Iterator &$iterator = null) 
157 157
 	{
158 158
 		$iterator = $iterator ? $iterator : new Iterator;
159 159
 
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 		}
164 164
 
165 165
 		// get the rows
166
-		$query = UserModel::find()->select(['uuid','username'])
166
+		$query = UserModel::find()->select(['uuid', 'username'])
167 167
 			->limit($iterator->length)
168 168
 			->offset($iterator->start)
169 169
 			->orderBy('username');
Please login to merge, or discard this patch.
Braces   +21 added lines, -14 removed lines patch added patch discarded remove patch
@@ -29,8 +29,9 @@  discard block
 block discarded – undo
29 29
 	{
30 30
 		$auth = neon()->authManager;
31 31
 		$authRole = $auth->createRole($role);
32
-		if ($authRole)
33
-			$auth->add($authRole);
32
+		if ($authRole) {
33
+					$auth->add($authRole);
34
+		}
34 35
 	}
35 36
 
36 37
 	/**
@@ -40,8 +41,9 @@  discard block
 block discarded – undo
40 41
 	{
41 42
 		$auth = neon()->authManager;
42 43
 		$authRole = $auth->getRole($role);
43
-		if ($authRole)
44
-			$auth->remove($authRole);
44
+		if ($authRole) {
45
+					$auth->remove($authRole);
46
+		}
45 47
 	}
46 48
 
47 49
 	/**
@@ -70,8 +72,9 @@  discard block
 block discarded – undo
70 72
 		$user->username = $username;
71 73
 		$user->email = $email;
72 74
 		$user->setPassword($password);
73
-		if ($superuser && neon()->user->isSuper())
74
-			$user->super = $superuser;
75
+		if ($superuser && neon()->user->isSuper()) {
76
+					$user->super = $superuser;
77
+		}
75 78
 		$user->generateAuthKey();
76 79
 		$success = $user->save();
77 80
 		if ($success) {
@@ -117,8 +120,9 @@  discard block
 block discarded – undo
117 120
 			foreach ($newValues as $key=>$value) {
118 121
 				$user->$key = $value;
119 122
 			}
120
-			if (isset($changes['superuser']))
121
-				$user->__set_super($changes['superuser']);
123
+			if (isset($changes['superuser'])) {
124
+							$user->__set_super($changes['superuser']);
125
+			}
122 126
 			$success = $user->save();
123 127
 			return $success ? true : $user->errors;
124 128
 		}
@@ -132,8 +136,9 @@  discard block
 block discarded – undo
132 136
 	public function destroyUser($uuid)
133 137
 	{
134 138
 		$user = $this->findUserModel($uuid);
135
-		if ($user)
136
-			$user->delete();
139
+		if ($user) {
140
+					$user->delete();
141
+		}
137 142
 	}
138 143
 
139 144
 
@@ -168,15 +173,17 @@  discard block
 block discarded – undo
168 173
 			->offset($iterator->start)
169 174
 			->orderBy('username');
170 175
 
171
-		if ($where)
172
-			$query->where($where);
176
+		if ($where) {
177
+					$query->where($where);
178
+		}
173 179
 		
174 180
 		$userRows = $query->all();
175 181
 
176 182
 		// and return in required format
177 183
 		$users = [];
178
-		foreach ($userRows as $ur)
179
-			$users[$ur['uuid']] = $ur['username'];
184
+		foreach ($userRows as $ur) {
185
+					$users[$ur['uuid']] = $ur['username'];
186
+		}
180 187
 		return $users;
181 188
 	}
182 189
 
Please login to merge, or discard this patch.
neon/user/services/User.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 	 * @param int $size
227 227
 	 * @return string
228 228
 	 */
229
-	public function getGuestUserImageUrl($size=40)
229
+	public function getGuestUserImageUrl($size = 40)
230 230
 	{
231 231
 		return "//www.gravatar.com/avatar?d=mm&s=$size";
232 232
 	}
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 	/**
235 235
 	 * @inheritdoc
236 236
 	 */
237
-	public function getImageUrl($size=40)
237
+	public function getImageUrl($size = 40)
238 238
 	{
239 239
 		return $this->noIdentity() ? $this->getGuestUserImageUrl($size) : $this->identity->getImageUrl($size);
240 240
 	}
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 	/**
277 277
 	 * @inheritdoc
278 278
 	 */
279
-	public function getHomeUrl($role=null)
279
+	public function getHomeUrl($role = null)
280 280
 	{
281 281
 		return $this->noIdentity() ? null : $this->identity->getHomeUrl($role);
282 282
 	}
@@ -295,13 +295,13 @@  discard block
 block discarded – undo
295 295
 		foreach ($userRoles as $ur) {
296 296
 			if (array_key_exists('homeUrl', $appRoles[$ur])) {
297 297
 				$url = $appRoles[$ur]['homeUrl'];
298
-				return parent::getReturnUrl( is_array($url) ? $url : [ $url ]);
298
+				return parent::getReturnUrl(is_array($url) ? $url : [$url]);
299 299
 			}
300 300
 		}
301 301
 
302 302
 		// use the default or application set one
303 303
 		if ($defaultUrl)
304
-			return parent::getReturnUrl( is_array($defaultUrl) ? $defaultUrl : [ $defaultUrl ] );
304
+			return parent::getReturnUrl(is_array($defaultUrl) ? $defaultUrl : [$defaultUrl]);
305 305
 
306 306
 		return parent::getReturnUrl();
307 307
 	}
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -107,8 +107,9 @@  discard block
 block discarded – undo
107 107
 				$log = "User '$id' logged in from $ip. Session not enabled.";
108 108
 			}
109 109
 
110
-			if (neon()->getRequest()->enableCsrfValidation)
111
-				$this->regenerateCsrfToken();
110
+			if (neon()->getRequest()->enableCsrfValidation) {
111
+							$this->regenerateCsrfToken();
112
+			}
112 113
 
113 114
 			\Yii::info($log, __METHOD__);
114 115
 			$this->afterLogin($identity, false, $duration);
@@ -300,8 +301,9 @@  discard block
 block discarded – undo
300 301
 		}
301 302
 
302 303
 		// use the default or application set one
303
-		if ($defaultUrl)
304
-			return parent::getReturnUrl( is_array($defaultUrl) ? $defaultUrl : [ $defaultUrl ] );
304
+		if ($defaultUrl) {
305
+					return parent::getReturnUrl( is_array($defaultUrl) ? $defaultUrl : [ $defaultUrl ] );
306
+		}
305 307
 
306 308
 		return parent::getReturnUrl();
307 309
 	}
Please login to merge, or discard this patch.
neon/user/services/UserInvite.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
 				return neon()->mailer->compose($templates, $templateData)
50 50
 					->setTo($user->email)
51 51
 					->setFrom([$fromAddress => $fromName])
52
-					->setSubject($siteName.' invitation for ' . $user->email)
52
+					->setSubject($siteName.' invitation for '.$user->email)
53 53
 					->send();
54 54
 			}
55 55
 		}
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,8 +27,9 @@
 block discarded – undo
27 27
 				$fromName = setting('admin', 'fromEmailName', neon()->name);
28 28
 				$fromAddress = setting('admin', 'fromEmailAddress', 'system@'.neon()->request->getHostName());
29 29
 				
30
-				if (!$fromAddress)
31
-					throw new \Exception('The From Address needs to be set in the admin section for emails');
30
+				if (!$fromAddress) {
31
+									throw new \Exception('The From Address needs to be set in the admin section for emails');
32
+				}
32 33
 
33 34
 				$templates = [
34 35
 					'html' => '@neon/user/views/mail/userInviteToken-html',
Please login to merge, or discard this patch.
neon/user/plugins/smarty/function.getUser.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,6 +10,6 @@
 block discarded – undo
10 10
  */
11 11
 function smarty_function_getUser($params, $template)
12 12
 {
13
-	$assign = isset($params['assign'])?$params['assign']:'user';
13
+	$assign = isset($params['assign']) ? $params['assign'] : 'user';
14 14
 	$template->assign($assign, neon()->user);
15 15
 }
Please login to merge, or discard this patch.
neon/user/web/DbSession.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
15 15
  */
16 16
 class DbSession extends \yii\web\DbSession
17 17
 {
18
-	protected function composeFields($id=null, $data=null)
18
+	protected function composeFields($id = null, $data = null)
19 19
 	{
20 20
 		// NOTE: do not interact with the identity inside this call
21 21
 		// this will trigger a "session_regenerate_id(): Cannot call session save handler in a recursive manner" error
Please login to merge, or discard this patch.
neon/user/controllers/IndexController.php 1 patch
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -103,12 +103,14 @@
 block discarded – undo
103 103
 			if ($loggedInUser->isSuper()) {
104 104
 				if ($loggedInUser->getId() != $id) {
105 105
 					$user = $this->findModel($id);
106
-					if ($user->delete())
107
-						neon()->session->setFlash('success', 'The user has been successfully deleted');
108
-					else
109
-						neon()->session->setFlash('error', 'Something went wrong while trying to delete the user');
110
-				} else
111
-					neon()->session->setFlash('error', 'Sorry, you cannot delete yourself from the system.');
106
+					if ($user->delete()) {
107
+											neon()->session->setFlash('success', 'The user has been successfully deleted');
108
+					} else {
109
+											neon()->session->setFlash('error', 'Something went wrong while trying to delete the user');
110
+					}
111
+				} else {
112
+									neon()->session->setFlash('error', 'Sorry, you cannot delete yourself from the system.');
113
+				}
112 114
 				return $this->redirect(['/user/index/index']);
113 115
 			}
114 116
 			neon()->session->setFlash('error', 'You do not have permissions to delete the user');
Please login to merge, or discard this patch.