From 9229d7705e17abdfc6f9d197de4c206f4bcb3da6 Mon Sep 17 00:00:00 2001 From: Yevgeny Tomenko Date: Thu, 19 Oct 2023 19:47:08 +0300 Subject: [PATCH] (chore) coding standards --- phpstan-baseline.neon | 5 ---- .../Traits/OneTimePasswordVerifyTrait.php | 5 +--- .../Traits/PasswordManagementTrait.php | 6 +--- src/Mailer/UsersMailer.php | 28 +++++++++---------- src/Model/Behavior/PasswordBehavior.php | 8 +++--- .../TestApp/Mailer/OverrideMailer.php | 2 +- 6 files changed, 21 insertions(+), 33 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 52b966521..2dc114261 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 diff --git a/src/Controller/Traits/OneTimePasswordVerifyTrait.php b/src/Controller/Traits/OneTimePasswordVerifyTrait.php index 9151e1b8d..336d4edf4 100644 --- a/src/Controller/Traits/OneTimePasswordVerifyTrait.php +++ b/src/Controller/Traits/OneTimePasswordVerifyTrait.php @@ -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); diff --git a/src/Controller/Traits/PasswordManagementTrait.php b/src/Controller/Traits/PasswordManagementTrait.php index 4aaf8c156..56a1383f1 100644 --- a/src/Controller/Traits/PasswordManagementTrait.php +++ b/src/Controller/Traits/PasswordManagementTrait.php @@ -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'); diff --git a/src/Mailer/UsersMailer.php b/src/Mailer/UsersMailer.php index 468407e5e..ca5a25de3 100644 --- a/src/Mailer/UsersMailer.php +++ b/src/Mailer/UsersMailer.php @@ -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, @@ -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, diff --git a/src/Model/Behavior/PasswordBehavior.php b/src/Model/Behavior/PasswordBehavior.php index cbc93c523..22156e1dc 100644 --- a/src/Model/Behavior/PasswordBehavior.php +++ b/src/Model/Behavior/PasswordBehavior.php @@ -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); diff --git a/tests/test_app/TestApp/Mailer/OverrideMailer.php b/tests/test_app/TestApp/Mailer/OverrideMailer.php index 5b5cb79c8..ae9d5dbba 100644 --- a/tests/test_app/TestApp/Mailer/OverrideMailer.php +++ b/tests/test_app/TestApp/Mailer/OverrideMailer.php @@ -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');