Skip to content

Commit f15fd34

Browse files
author
EllaiSys
committed
fix: sonar lint findings
1 parent 0e77939 commit f15fd34

16 files changed

+65
-60
lines changed

config/cognito.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@
175175

176176
/*
177177
|--------------------------------------------------------------------------
178-
| Cognito Challenge Status Names for Forced Access.
178+
| Cognito Challenge Status Names for Forced Password Change.
179179
|--------------------------------------------------------------------------
180180
|
181181
| This option controls the package action based on the Challenge Status
182182
| received from the AWS Cognito Authentication. If the challenge status
183-
| is 'NEW_PASSWORD_CHALLENGE' and/or 'RESET_REQUIRED_PASSWORD', the
184-
| configuration that follows below will execute.
183+
| is 'NEW_PASSWORD_CHALLENGE' and/or 'RESET_REQUIRED_PASSWORD', this
184+
| configuration will force the user to change their password.
185185
|
186186
*/
187187
'forced_challenge_names' => [
@@ -191,7 +191,8 @@
191191

192192
/*
193193
|--------------------------------------------------------------------------
194-
| Force Password Change by the User based on Cognito Status in Web Request (Session Guard)
194+
| Force Password Change by the User based on Cognito Status in Web Request
195+
| (Session Guard)
195196
|--------------------------------------------------------------------------
196197
|
197198
| This setting controls the action, in case the AWS Cognito authentication
@@ -271,7 +272,7 @@
271272
| Allow new user to set the password and have verified
272273
|--------------------------------------------------------------------------
273274
|
274-
| This option enables the user to set the password and have that verified
275+
| This option enables the user to set the password and have that verified
275276
| during the to invitation for the new user. The default value is set to true.
276277
|
277278
*/

src/AwsCognito.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class AwsCognito
6161

6262
/**
6363
* The AwsCognito Claim token
64-
*
64+
*
6565
* @var \Ellaisys\Cognito\AwsCognitoClaim|null
6666
*/
6767
protected $claim;
@@ -98,8 +98,6 @@ public function __construct(AwsCognitoManager $manager, Parser $parser)
9898
public static function ignoreMigrations(): void
9999
{
100100
static::$runsMigrations = false;
101-
102-
return;
103101
} //Function ends
104102

105103

@@ -220,7 +218,7 @@ public function setChallengeData(string $key, $data, int $durationInSecs=3600)
220218
*
221219
* @return \Ellaisys\Cognito\AwsCognito
222220
*/
223-
public function unsetToken($forceForever = false)
221+
public function unsetToken(bool $forceForever = false)
224222
{
225223
$tokenKey = $this->token->get();
226224
$this->manager->release($tokenKey);
@@ -314,4 +312,4 @@ public function storeToken()
314312
return $this->manager->encode($this->claim)->store();
315313
} //Function ends
316314

317-
} //Class ends
315+
} //Class ends

src/AwsCognitoClaim.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function __construct(AwsResult $result, Authenticatable $user=null) {
8686
$this->tokenDecode = $decodedToken;
8787

8888
} catch(Exception $e) {
89+
Log::error('CognitoClaim:__construct:Exception');
8990
throw $e;
9091
} //Try-catch ends
9192
} //Function ends
@@ -177,4 +178,4 @@ public function __toString()
177178
return $this->getToken();
178179
} //Function ends
179180

180-
} //Class ends
181+
} //Class ends

src/AwsCognitoClient.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ public function authenticate($username, $password)
227227

228228
$response = $this->client->adminInitiateAuth($payload);
229229
} catch (CognitoIdentityProviderException $exception) {
230+
Log::error('CognitoIdentityProvider:adminInitiateAuth:Exception');
230231
throw $exception;
231232
} //Try-catch ends
232233

@@ -385,6 +386,7 @@ public function adminListGroupsForUser(string $username)
385386
);
386387
return $groups;
387388
} catch (CognitoIdentityProviderException $e) {
389+
Log::error('CognitoIdentityProvider:adminListGroupsForUser:Exception');
388390
throw $e;
389391
} //Try-catch ends
390392

@@ -410,6 +412,7 @@ public function adminAddUserToGroup(string $username, string $groupname)
410412
'Username' => $username
411413
]);
412414
} catch (CognitoIdentityProviderException $e) {
415+
Log::error('CognitoIdentityProvider:adminAddUserToGroup:Exception');
413416
throw $e;
414417
} //Try-catch ends
415418

@@ -435,7 +438,7 @@ public function inviteUser(string $username, string $password=null, array $attri
435438
//Validate phone for MFA
436439
if (config('cognito.mfa_setup')=="MFA_ENABLED") {
437440
if (empty($attributes['phone_number'])) { throw new HttpException(400, 'ERROR_MFA_ENABLED_PHONE_MISSING'); }
438-
} //End if
441+
} //End if
439442

440443
//Force validate email
441444
if ($attributes['email']) {
@@ -636,7 +639,7 @@ public function confirmUserSignUp($username, $confirmationCode)
636639
return 'validation.invalid_token';
637640
} //End if
638641

639-
if ($e->getAwsErrorCode() === 'NotAuthorizedException' AND $e->getAwsErrorMessage() === 'User cannot be confirmed. Current status is CONFIRMED') {
642+
if ($e->getAwsErrorCode() === 'NotAuthorizedException' && $e->getAwsErrorMessage() === 'User cannot be confirmed. Current status is CONFIRMED') {
640643
return 'validation.confirmed';
641644
} //End if
642645

@@ -698,6 +701,7 @@ public function setUserAttributes($username, array $attributes)
698701
//Execute the payload
699702
$this->client->AdminUpdateUserAttributes($payload);
700703
} catch (CognitoIdentityProviderException $e) {
704+
Log::error('CognitoIdentityProvider:adminUpdateUserAttributes:Exception');
701705
throw $e;
702706
} //End try
703707

@@ -713,7 +717,7 @@ public function setUserAttributes($username, array $attributes)
713717
* @param string $session
714718
* @param string $challengeValue
715719
* @param string $username
716-
*
720+
*
717721
* @return \Aws\Result
718722
*/
719723
protected function adminRespondToAuthChallenge(
@@ -766,6 +770,7 @@ protected function adminRespondToAuthChallenge(
766770
//Execute the payload
767771
$response = $this->client->adminRespondToAuthChallenge($payload);
768772
} catch (CognitoIdentityProviderException $e) {
773+
Log::error('CognitoIdentityProvider:adminRespondToAuthChallenge:Exception');
769774
throw $e;
770775
} //Try-catch ends
771776

@@ -837,6 +842,7 @@ public function getUserByAccessToken(string $token)
837842
'AccessToken' => $token
838843
]);
839844
} catch (CognitoIdentityProviderException $e) {
845+
Log::error('CognitoIdentityProvider:getUserByAccessToken:Exception');
840846
throw $e;
841847
} //Try-catch ends
842848

@@ -916,6 +922,7 @@ public function refreshToken(string $username, string $refreshToken)
916922
// Reuse same refreshToken
917923
$response['AuthenticationResult']['RefreshToken'] = $refreshToken;
918924
} catch (CognitoIdentityProviderException $e) {
925+
Log::error('CognitoIdentityProvider:refreshToken:Exception');
919926
throw $e;
920927
} //Try-catch ends
921928

@@ -940,6 +947,7 @@ public function revokeToken(string $refreshToken)
940947
'Token' => $refreshToken
941948
]);
942949
} catch (Exception $e) {
950+
Log::error('CognitoIdentityProvider:revokeToken:Exception');
943951
throw $e;
944952
} //Try-catch ends
945953
return true;

src/AwsCognitoManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class AwsCognitoManager
4747

4848
/**
4949
* The AwsCognito Claim token
50-
*
50+
*
5151
* @var \Ellaisys\Cognito\AwsCognitoClaim|null
5252
*/
5353
protected $claim;
@@ -136,7 +136,7 @@ public function release(string $token)
136136

137137
/**
138138
* Save challenge object
139-
*
139+
*
140140
* @param string $key
141141
* @param mixed $data
142142
* @param int $durationInSecs
@@ -161,4 +161,4 @@ public function fetchData(string $key)
161161
return $data?json_decode($data, true):null;
162162
} //Function ends
163163

164-
} //Class ends
164+
} //Class ends

src/Contracts/Storage/StorageContract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ public function destroy($key);
5353
* @return void
5454
*/
5555
public function flush();
56-
}
56+
}

src/Exceptions/InvalidTokenException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ public function render($request, Throwable $exception)
3333
return parent::render($request, $exception);
3434
}
3535

36-
} //Class ends
36+
} //Class ends

src/Exceptions/InvalidUserFieldException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ public function render($request, Throwable $exception)
3535
return parent::render($request, $exception);
3636
}
3737

38-
} //Class ends
38+
} //Class ends

src/Exceptions/InvalidUserModelException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ public function render($request, Throwable $exception)
3232
return parent::render($request, $exception);
3333
}
3434

35-
} //Class ends
35+
} //Class ends

src/Exceptions/NoTokenException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ public function render($request, Throwable $exception)
3333
return parent::render($request, $exception);
3434
}
3535

36-
} //Class ends
36+
} //Class ends

0 commit comments

Comments
 (0)