php-cs-fixer fix

This commit is contained in:
Lorenzo Milesi
2022-12-29 22:58:51 +01:00
parent fdb53cfe7a
commit 406fa591f3
4 changed files with 61 additions and 62 deletions

View File

@ -1,5 +1,14 @@
<?php <?php
/*
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Da\User\Controller\api\v1; namespace Da\User\Controller\api\v1;
use Da\User\Event\UserEvent; use Da\User\Event\UserEvent;
@ -87,30 +96,11 @@ class AdminController extends ActiveController
{ {
// Get and then remove some default actions // Get and then remove some default actions
$actions = parent::actions(); $actions = parent::actions();
unset($actions['create']); unset($actions['create'], $actions['update'], $actions['delete']);
unset($actions['update']);
unset($actions['delete']);
return $actions; return $actions;
} }
/**
* {@inheritdoc}
*/
protected function verbs()
{
// Get parent verbs
$verbs = parent::verbs();
// Add new verbs and return
$verbs['update-profile'] = ['PUT', 'PATCH'];
$verbs['assignments'] = ['GET'];
$verbs['confirm'] = ['PUT', 'PATCH'];
$verbs['block'] = ['PUT', 'PATCH'];
$verbs['password-reset'] = ['PUT', 'PATCH'];
$verbs['force-password-change'] = ['PUT', 'PATCH'];
return $verbs;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -149,9 +139,9 @@ class AdminController extends ActiveController
} }
} }
/** /**
* Override beforeAction. If the api is called with parameter username get the id of the user and set it in query params * Override beforeAction. If the api is called with parameter username get the id of the user and set it in query params
* @param mixed $action
*/ */
public function beforeAction($action) public function beforeAction($action)
{ {
@ -278,8 +268,7 @@ class AdminController extends ActiveController
if ($user->delete()) { if ($user->delete()) {
$this->trigger(ActiveRecord::EVENT_AFTER_DELETE, $event); $this->trigger(ActiveRecord::EVENT_AFTER_DELETE, $event);
Yii::$app->getResponse()->setStatusCode(204); // 204 = No Content Yii::$app->getResponse()->setStatusCode(204); // 204 = No Content
} } else {
else {
$this->throwServerError(); $this->throwServerError();
} }
} }
@ -369,10 +358,9 @@ class AdminController extends ActiveController
$this->trigger(UserEvent::EVENT_AFTER_CONFIRMATION, $event); $this->trigger(UserEvent::EVENT_AFTER_CONFIRMATION, $event);
return $user; return $user;
} }
else {
$this->throwServerError(); $this->throwServerError();
} }
}
/** /**
* Block and unblock the user. * Block and unblock the user.
@ -404,10 +392,9 @@ class AdminController extends ActiveController
if ($this->make(UserBlockService::class, [$user, $event, $this])->run() || $user->hasErrors()) { if ($this->make(UserBlockService::class, [$user, $event, $this])->run() || $user->hasErrors()) {
return $user; return $user;
} }
else {
$this->throwServerError(); $this->throwServerError();
} }
}
/** /**
* Reset password. * Reset password.
@ -430,10 +417,9 @@ class AdminController extends ActiveController
if ($this->make(PasswordRecoveryService::class, [$user->email, $mailService])->run()) { if ($this->make(PasswordRecoveryService::class, [$user->email, $mailService])->run()) {
return $user; return $user;
} }
else {
$this->throwServerError(); $this->throwServerError();
} }
}
/** /**
* Forces the user to change password at next login. * Forces the user to change password at next login.
@ -455,15 +441,32 @@ class AdminController extends ActiveController
if ($this->make(PasswordExpireService::class, [$user])->run()) { if ($this->make(PasswordExpireService::class, [$user])->run()) {
return $user; return $user;
} }
else {
$this->throwServerError(); $this->throwServerError();
} }
/**
* {@inheritdoc}
*/
protected function verbs()
{
// Get parent verbs
$verbs = parent::verbs();
// Add new verbs and return
$verbs['update-profile'] = ['PUT', 'PATCH'];
$verbs['assignments'] = ['GET'];
$verbs['confirm'] = ['PUT', 'PATCH'];
$verbs['block'] = ['PUT', 'PATCH'];
$verbs['password-reset'] = ['PUT', 'PATCH'];
$verbs['force-password-change'] = ['PUT', 'PATCH'];
return $verbs;
} }
/** /**
* Handle server error (with default Yii2 response). * Handle server error (with default Yii2 response).
* @return void
* @throws ServerErrorHttpException * @throws ServerErrorHttpException
* @return void
*/ */
protected function throwServerError() protected function throwServerError()
{ {
@ -472,14 +475,11 @@ class AdminController extends ActiveController
/** /**
* Handle 404 error for user (usually if the entered ID is not valid). * Handle 404 error for user (usually if the entered ID is not valid).
* @return void
* @throws NotFoundHttpException * @throws NotFoundHttpException
* @return void
*/ */
protected function throwUser404() protected function throwUser404()
{ {
throw new NotFoundHttpException(Yii::t('usuario', 'User not found.')); throw new NotFoundHttpException(Yii::t('usuario', 'User not found.'));
} }
} }

View File

@ -188,7 +188,6 @@ class LoginForm extends Model
return $this->user; return $this->user;
} }
/** /**
* @param IdentityInterface $user * @param IdentityInterface $user
* @return User * @return User