Skip to content

Commit

Permalink
(chore) coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
skie committed Oct 19, 2023
1 parent 98dcd77 commit 9229d77
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 33 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ parameters:
count: 1
path: src/Controller/UsersController.php

-
message: "#^Parameter \\#1 \\$message of method Cake\\\\Controller\\\\Controller\\:\\:log\\(\\) expects string, Exception given\\.$#"
count: 1
path: src/Controller/UsersController.php

-
message: "#^Parameter \\#1 \\$object of method Cake\\\\Controller\\\\Controller\\:\\:paginate\\(\\) expects Cake\\\\ORM\\\\Query\\|Cake\\\\ORM\\\\Table\\|string\\|null, Cake\\\\Datasource\\\\RepositoryInterface given\\.$#"
count: 1
Expand Down
5 changes: 1 addition & 4 deletions src/Controller/Traits/OneTimePasswordVerifyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ protected function onPostVerifyCodeOkay($loginAction, $user)
unset($user['secret']);

if (!$user['secret_verified']) {
$this->getUsersTable()->updateQuery()
->set(['secret_verified' => true])
->where(['id' => $user['id']])
->execute();
$this->getUsersTable()->updateAll(['secret_verified' => true], ['id' => $user['id']]);
}

$this->getRequest()->getSession()->delete(AuthenticationService::TWO_FACTOR_VERIFY_SESSION_KEY);
Expand Down
6 changes: 1 addition & 5 deletions src/Controller/Traits/PasswordManagementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,7 @@ public function resetOneTimePasswordAuthenticator($id = null)
{
if ($this->getRequest()->is('post')) {
try {
$query = $this->getUsersTable()->updateQuery();
$query
->set(['secret_verified' => false, 'secret' => null])
->where(['id' => $id]);
$query->execute();
$query = $this->getUsersTable()->updateAll(['secret_verified' => false, 'secret' => null], ['id' => $id]);

$message = __d('cake_d_c/users', 'Google Authenticator token was successfully reset');
$this->Flash->success($message, 'default');
Expand Down
28 changes: 14 additions & 14 deletions src/Mailer/UsersMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ class UsersMailer extends Mailer
* @param \Cake\Datasource\EntityInterface $user User entity
* @return void
*/
protected function validation(EntityInterface $user, $options = [])
protected function validation(EntityInterface $user, array $options = [])
{
$firstName = isset($user['first_name']) ? $user['first_name'] . ', ' : '';
// un-hide the token to be able to send it in the email content
$user->setHidden(['password', 'token_expires', 'api_token']);
$subject = __d('cake_d_c/users', 'Your account validation link');

if (isset($options['linkGenerator']) && is_callable($options['linkGenerator'])) {
$generator = $options['linkGenerator'];
$link = $generator($user['token']);
} else {
$link = UsersUrl::actionUrl('validateEmail', [
if (isset($options['linkGenerator']) && is_callable($options['linkGenerator'])) {
$generator = $options['linkGenerator'];
$link = $generator($user['token']);
} else {
$link = UsersUrl::actionUrl('validateEmail', [
'_full' => true,
$user['token'],
]);
}
}

$viewVars = [
'activationUrl' => $link,
Expand All @@ -65,22 +65,22 @@ protected function validation(EntityInterface $user, $options = [])
* @param \Cake\Datasource\EntityInterface $user User entity
* @return void
*/
protected function resetPassword(EntityInterface $user, $options = [])
protected function resetPassword(EntityInterface $user, array $options = [])
{
$firstName = isset($user['first_name']) ? $user['first_name'] . ', ' : '';
$subject = __d('cake_d_c/users', '{0}Your reset password link', $firstName);
// un-hide the token to be able to send it in the email content
$user->setHidden(['password', 'token_expires', 'api_token']);

if (isset($options['linkGenerator']) && is_callable($options['linkGenerator'])) {
$generator = $options['linkGenerator'];
$link = $generator($user['token']);
} else {
$link = UsersUrl::actionUrl('resetPassword', [
if (isset($options['linkGenerator']) && is_callable($options['linkGenerator'])) {
$generator = $options['linkGenerator'];
$link = $generator($user['token']);
} else {
$link = UsersUrl::actionUrl('resetPassword', [
'_full' => true,
$user['token'],
]);
}
}

$viewVars = [
'activationUrl' => $link,
Expand Down
8 changes: 4 additions & 4 deletions src/Model/Behavior/PasswordBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public function resetToken($reference, array $options = [])
$user->updateToken($expiration);
$saveResult = $this->_table->save($user);
if ($options['sendEmail'] ?? false) {
$emailOptions = [];
if (isset($options['linkGenerator']) && is_callable($options['linkGenerator'])) {
$emailOptions['linkGenerator'] = $options['linkGenerator'];
}
$emailOptions = [];
if (isset($options['linkGenerator']) && is_callable($options['linkGenerator'])) {
$emailOptions['linkGenerator'] = $options['linkGenerator'];
}
switch ($options['type'] ?? null) {
case 'email':
$this->_sendValidationEmail($user, $emailOptions);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_app/TestApp/Mailer/OverrideMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class OverrideMailer extends UsersMailer
* @param EntityInterface $user
* @return array|void
*/
public function resetPassword(EntityInterface $user, $options = [])
public function resetPassword(EntityInterface $user, array $options = [])
{
parent::resetPassword($user);
$this->setSubject('This is the new subject');
Expand Down

0 comments on commit 9229d77

Please sign in to comment.