diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index a8d654d..4f018a4 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -69,6 +69,9 @@ jobs: - name: Run tests run: XDEBUG_MODE=coverage php vendor/bin/codecept run --coverage --coverage-xml + - name: Run static code analysis + run: vendor/bin/phpstan analyse + - name: Archive failed tests artifacts - test output & log uses: actions/upload-artifact@v2 if: failure() diff --git a/composer.json b/composer.json index 2c478dd..df734da 100644 --- a/composer.json +++ b/composer.json @@ -52,6 +52,8 @@ "2amigos/qrcode-library": "Needed if you want to enable 2FA with QR Code generation. Require version ^1.1" }, "require-dev": { + "2amigos/2fa-library": "^2.0", + "2amigos/qrcode-library": "^2.0", "friendsofphp/php-cs-fixer": "^3", "php": ">=7.4", "yiisoft/yii2-symfonymailer": "~2.0.0", @@ -63,7 +65,8 @@ "codeception/module-filesystem": "^1.0", "codeception/module-yii2": "^1.1", "codeception/module-asserts": "^1.1", - "codeception/module-db": "^1.0" + "codeception/module-db": "^1.0", + "phpstan/phpstan": "^1.8" }, "autoload": { "psr-4": { @@ -76,6 +79,9 @@ } }, "config": { + "platform": { + "php": "7.4" + }, "preferred-install": { "*": "auto" }, diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..82b0ee8 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,8 @@ +parameters: + level: 1 + paths: + - src + excludePaths: + - 'src/resources/i18n/*' + bootstrapFiles: + - stan_autoload.php diff --git a/src/User/Event/ResetPasswordEvent.php b/src/User/Event/ResetPasswordEvent.php index 188553d..4253a5a 100644 --- a/src/User/Event/ResetPasswordEvent.php +++ b/src/User/Event/ResetPasswordEvent.php @@ -19,7 +19,7 @@ use yii\base\Event; * @property-read Token $token * @property-read RecoveryForm $form */ -class ResetPasswordEvent extends Event +final class ResetPasswordEvent extends Event { const EVENT_BEFORE_TOKEN_VALIDATE = 'beforeTokenValidate'; const EVENT_AFTER_TOKEN_VALIDATE = 'afterTokenValidate'; diff --git a/src/User/Service/SocialNetworkAuthenticateService.php b/src/User/Service/SocialNetworkAuthenticateService.php index da80f65..ded5f47 100644 --- a/src/User/Service/SocialNetworkAuthenticateService.php +++ b/src/User/Service/SocialNetworkAuthenticateService.php @@ -67,6 +67,7 @@ class SocialNetworkAuthenticateService implements ServiceInterface $event = Yii::createObject(SocialNetworkAuthEvent::class, [$account, $this->client]); $this->controller->trigger(SocialNetworkAuthEvent::EVENT_BEFORE_AUTHENTICATE, $event); + $result = false; if ($account->user instanceof User) { if ($account->user->getIsBlocked()) { @@ -75,12 +76,15 @@ class SocialNetworkAuthenticateService implements ServiceInterface } else { Yii::$app->user->login($account->user, $this->controller->module->rememberLoginLifespan); $this->authAction->setSuccessUrl(Yii::$app->getUser()->getReturnUrl()); + $result = true; } } else { $this->authAction->setSuccessUrl($account->getConnectionUrl()); + $result = true; } $this->controller->trigger(SocialNetworkAuthEvent::EVENT_AFTER_AUTHENTICATE, $event); + return $result; } protected function createAccount() diff --git a/src/User/Service/SwitchIdentityService.php b/src/User/Service/SwitchIdentityService.php index 842197b..4038c33 100644 --- a/src/User/Service/SwitchIdentityService.php +++ b/src/User/Service/SwitchIdentityService.php @@ -65,5 +65,6 @@ class SwitchIdentityService implements ServiceInterface /** @var IdentityInterface $user */ Yii::$app->user->switchIdentity($user, $session->timeout); $this->controller->trigger(UserEvent::EVENT_AFTER_SWITCH_IDENTITY, $event); + return true; } } diff --git a/src/User/Service/UserCreateService.php b/src/User/Service/UserCreateService.php index a631d5e..5dc41ac 100644 --- a/src/User/Service/UserCreateService.php +++ b/src/User/Service/UserCreateService.php @@ -57,7 +57,7 @@ class UserCreateService implements ServiceInterface $model->confirmed_at = time(); $model->password = !empty($model->password) ? $model->password - : $this->securityHelper->generatePassword(8, $this->getModule('user')->minPasswordRequirements); + : $this->securityHelper->generatePassword(8, $this->getModule()->minPasswordRequirements); /** @var UserEvent $event */ $event = $this->make(UserEvent::class, [$model]); @@ -76,14 +76,14 @@ class UserCreateService implements ServiceInterface ['email' => $model->email] ); // from web display a flash message (if enabled) - if ($this->getModule()->enableFlashMessages === true && is_a(Yii::$app, yii\web\Application::class)) { + if ($this->getModule()->enableFlashMessages === true && is_a(Yii::$app, "yii\web\Application")) { Yii::$app->session->setFlash( 'warning', $error_msg ); } // if we're from console add an error to the model in order to return an error message - if (is_a(Yii::$app, yii\console\Application::class)) { + if (is_a(Yii::$app, "yii\console\Application")) { $model->addError('username', $error_msg); } $transaction->rollBack(); diff --git a/src/User/Service/UserRegisterService.php b/src/User/Service/UserRegisterService.php index 747d9eb..a48932e 100644 --- a/src/User/Service/UserRegisterService.php +++ b/src/User/Service/UserRegisterService.php @@ -51,7 +51,7 @@ class UserRegisterService implements ServiceInterface try { $model->confirmed_at = $this->getModule()->enableEmailConfirmation ? null : time(); $model->password = $this->getModule()->generatePasswords - ? $this->securityHelper->generatePassword(8, $this->getModule('user')->minPasswordRequirements) + ? $this->securityHelper->generatePassword(8, $this->getModule()->minPasswordRequirements) : $model->password; $event = $this->make(UserEvent::class, [$model]); diff --git a/src/User/Validator/AjaxRequestModelValidator.php b/src/User/Validator/AjaxRequestModelValidator.php index 6f3775e..a4ea712 100644 --- a/src/User/Validator/AjaxRequestModelValidator.php +++ b/src/User/Validator/AjaxRequestModelValidator.php @@ -32,9 +32,12 @@ class AjaxRequestModelValidator implements ValidatorInterface if ($request->getIsAjax() && $this->model->load($request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; - Yii::$app->response->data = ActiveForm::validate($this->model); + $result = ActiveForm::validate($this->model); + Yii::$app->response->data = $result; Yii::$app->response->send(); Yii::$app->end(); + return $result; } + return false; } } diff --git a/src/User/resources/views/admin/_account.php b/src/User/resources/views/admin/_account.php index db1d14a..e9d49e8 100644 --- a/src/User/resources/views/admin/_account.php +++ b/src/User/resources/views/admin/_account.php @@ -12,8 +12,8 @@ use yii\bootstrap\ActiveForm; use yii\helpers\Html; -/* @var yii\web\View $this */ -/* @var Da\User\Model\User $user */ +/** @var yii\web\View $this */ +/** @var Da\User\Model\User $user */ ?> diff --git a/src/User/resources/views/admin/_assignments.php b/src/User/resources/views/admin/_assignments.php index 4bf779b..293285c 100644 --- a/src/User/resources/views/admin/_assignments.php +++ b/src/User/resources/views/admin/_assignments.php @@ -11,9 +11,9 @@ use Da\User\Widget\AssignmentsWidget; -/* @var yii\web\View $this */ -/* @var Da\User\Model\User $user */ -/* @var string[] $params */ +/** @var yii\web\View $this */ +/** @var Da\User\Model\User $user */ +/** @var string[] $params */ ?> diff --git a/src/User/resources/views/admin/_info.php b/src/User/resources/views/admin/_info.php index cf64366..1b929e7 100644 --- a/src/User/resources/views/admin/_info.php +++ b/src/User/resources/views/admin/_info.php @@ -9,10 +9,9 @@ * the LICENSE file that was distributed with this source code. */ -/** - * @var yii\web\View - * @var \Da\User\Model\User $user - */ +/** @var yii\web\View $this */ +/** @var Da\User\Model\User $user */ + ?> beginContent('@Da/User/resources/views/admin/update.php', ['user' => $user]) ?> diff --git a/src/User/resources/views/admin/_user.php b/src/User/resources/views/admin/_user.php index 4dbf4d9..5e7303e 100644 --- a/src/User/resources/views/admin/_user.php +++ b/src/User/resources/views/admin/_user.php @@ -10,8 +10,8 @@ */ /** - * @var yii\widgets\ActiveForm - * @var \Da\User\Model\User $user + * @var yii\widgets\ActiveForm $form + * @var \Da\User\Model\User $user */ ?> diff --git a/src/User/resources/views/admin/index.php b/src/User/resources/views/admin/index.php index 552b460..d507e78 100644 --- a/src/User/resources/views/admin/index.php +++ b/src/User/resources/views/admin/index.php @@ -15,10 +15,10 @@ use yii\web\View; use yii\widgets\Pjax; /** - * @var $this yii\web\View - * @var $dataProvider yii\data\ActiveDataProvider - * @var $searchModel Da\User\Search\UserSearch - * @var $module Da\User\Module + * @var yii\web\View $this + * @var yii\data\ActiveDataProvider $dataProvider + * @var Da\User\Search\UserSearch $searchModel + * @var Da\User\Module $module */ $this->title = Yii::t('usuario', 'Manage users'); diff --git a/src/User/resources/views/mail/layouts/html.php b/src/User/resources/views/mail/layouts/html.php index 16f2f1c..96ba806 100644 --- a/src/User/resources/views/mail/layouts/html.php +++ b/src/User/resources/views/mail/layouts/html.php @@ -10,8 +10,8 @@ */ /** - * @var \yii\web\View - * @var yii\mail\BaseMessage $content + * @var \yii\web\View $this + * @var string $content */ ?> beginPage() ?> diff --git a/src/User/resources/views/mail/layouts/text.php b/src/User/resources/views/mail/layouts/text.php index 8982930..d5c064b 100644 --- a/src/User/resources/views/mail/layouts/text.php +++ b/src/User/resources/views/mail/layouts/text.php @@ -10,7 +10,9 @@ */ /** - * @var string main view render result +/** + * @var \yii\web\View $this + * @var string $content */ ?> diff --git a/src/User/resources/views/mail/text/confirmation.php b/src/User/resources/views/mail/text/confirmation.php index 5d3bef5..20a6928 100644 --- a/src/User/resources/views/mail/text/confirmation.php +++ b/src/User/resources/views/mail/text/confirmation.php @@ -10,7 +10,6 @@ */ /** - * @var \Da\User\Model\User * @var \Da\User\Model\Token $token */ ?> diff --git a/src/User/resources/views/mail/text/reconfirmation.php b/src/User/resources/views/mail/text/reconfirmation.php index 0280140..808139c 100644 --- a/src/User/resources/views/mail/text/reconfirmation.php +++ b/src/User/resources/views/mail/text/reconfirmation.php @@ -10,7 +10,7 @@ */ /** - * @var \Da\User\Model\Token + * @var \Da\User\Model\Token $token */ ?> = Yii::t('usuario', 'Hello') ?>, diff --git a/src/User/resources/views/mail/text/recovery.php b/src/User/resources/views/mail/text/recovery.php index 5f3a3a7..08a7210 100644 --- a/src/User/resources/views/mail/text/recovery.php +++ b/src/User/resources/views/mail/text/recovery.php @@ -10,7 +10,6 @@ */ /** - * @var \Da\User\Model\User * @var \Da\User\Model\Token $token */ ?> diff --git a/src/User/resources/views/mail/text/welcome.php b/src/User/resources/views/mail/text/welcome.php index d0d3234..484209a 100644 --- a/src/User/resources/views/mail/text/welcome.php +++ b/src/User/resources/views/mail/text/welcome.php @@ -10,10 +10,10 @@ */ /** - * @var \Da\User\Model\User $user + * @var \Da\User\Model\User $user * @var \Da\User\Model\Token $token - * @var \Da\User\Module $module - * @var bool $showPassword + * @var \Da\User\Module $module + * @var bool $showPassword */ ?> = Yii::t('usuario', 'Hello') ?>, diff --git a/src/User/resources/views/permission/_form.php b/src/User/resources/views/permission/_form.php index a5b559b..1ab6575 100644 --- a/src/User/resources/views/permission/_form.php +++ b/src/User/resources/views/permission/_form.php @@ -15,9 +15,9 @@ use yii\helpers\Html; use yii\widgets\ActiveForm; /** - * @var $this yii\web\View - * @var $model Da\User\Model\Permission - * @var $unassignedItems string[] + * @var yii\web\View $this + * @var Da\User\Model\Permission $model + * @var string[] $unassignedItems */ ?> diff --git a/src/User/resources/views/permission/create.php b/src/User/resources/views/permission/create.php index 90ef9e4..613a58a 100644 --- a/src/User/resources/views/permission/create.php +++ b/src/User/resources/views/permission/create.php @@ -10,9 +10,9 @@ */ /** - * @var \Da\User\Model\Permission - * @var $this yii\web\View - * @var $unassignedItems string[] + * @var yii\web\View $this + * @var Da\User\Model\Permission $model + * @var string[] $unassignedItems */ $this->title = Yii::t('usuario', 'Create new permission'); diff --git a/src/User/resources/views/permission/index.php b/src/User/resources/views/permission/index.php index 18c61a6..3dcfa5f 100644 --- a/src/User/resources/views/permission/index.php +++ b/src/User/resources/views/permission/index.php @@ -10,9 +10,9 @@ */ /** - * @var $dataProvider \yii\data\ActiveDataProvider - * @var $this yii\web\View - * @var $searchModel \Da\User\Search\PermissionSearch + * @var \yii\data\ActiveDataProvider $dataProvider + * @var yii\web\View $this + * @var \Da\User\Search\PermissionSearch $searchModel */ use yii\grid\ActionColumn; use yii\grid\GridView; diff --git a/src/User/resources/views/permission/update.php b/src/User/resources/views/permission/update.php index a553acb..592cf40 100644 --- a/src/User/resources/views/permission/update.php +++ b/src/User/resources/views/permission/update.php @@ -10,9 +10,9 @@ */ /** - * @var \Da\User\Model\Permission - * @var $this yii\web\View - * @var $unassignedItems string[] + * @var yii\web\View $this + * @var Da\User\Model\Permission $model + * @var string[] $unassignedItems */ $this->title = Yii::t('usuario', 'Update permission'); @@ -31,4 +31,3 @@ $this->params['breadcrumbs'][] = $this->title; ) ?> endContent() ?> - diff --git a/src/User/resources/views/role/_form.php b/src/User/resources/views/role/_form.php index 69403e2..33eb2e9 100644 --- a/src/User/resources/views/role/_form.php +++ b/src/User/resources/views/role/_form.php @@ -10,8 +10,8 @@ */ /** - * @var $this yii\web\View - * @var $model \Da\User\Model\Role + * @var yii\web\View $this + * @var \Da\User\Model\Role $model */ use Da\User\Helper\AuthHelper; diff --git a/src/User/resources/views/role/create.php b/src/User/resources/views/role/create.php index 3176627..354a780 100644 --- a/src/User/resources/views/role/create.php +++ b/src/User/resources/views/role/create.php @@ -10,9 +10,9 @@ */ /** - * @var \Da\User\Model\Role - * @var $this yii\web\View - * @var $unassignedItems string[] + * @var yii\web\View $this + * @var \Da\User\Model\Role $model + * @var string[] $unassignedItems */ $this->title = Yii::t('usuario', 'Create new role'); $this->params['breadcrumbs'][] = $this->title; diff --git a/src/User/resources/views/role/index.php b/src/User/resources/views/role/index.php index e18b817..422d56e 100644 --- a/src/User/resources/views/role/index.php +++ b/src/User/resources/views/role/index.php @@ -14,9 +14,9 @@ use yii\grid\GridView; use yii\helpers\Url; /** - * @var $dataProvider array - * @var $searchModel \Da\User\Search\RoleSearch - * @var $this yii\web\View + * @var \yii\data\DataProviderInterface $dataProvider + * @var \Da\User\Search\RoleSearch $searchModel + * @var yii\web\View $this */ $this->title = Yii::t('usuario', 'Roles'); diff --git a/src/User/resources/views/role/update.php b/src/User/resources/views/role/update.php index b9ccc34..b809f3b 100644 --- a/src/User/resources/views/role/update.php +++ b/src/User/resources/views/role/update.php @@ -10,9 +10,9 @@ */ /** + * @var yii\web\View $this * @var \Da\User\Model\Role $model - * @var $this yii\web\View - * @var $unassignedItems string[] + * @var string[] $unassignedItems */ $this->title = Yii::t('usuario', 'Update role'); $this->params['breadcrumbs'][] = $this->title; diff --git a/src/User/resources/views/rule/_form.php b/src/User/resources/views/rule/_form.php index 37fc54a..498a0a8 100644 --- a/src/User/resources/views/rule/_form.php +++ b/src/User/resources/views/rule/_form.php @@ -1,8 +1,8 @@ title = Yii::t('usuario', 'Create new rule'); $this->params['breadcrumbs'][] = $this->title; diff --git a/src/User/resources/views/rule/index.php b/src/User/resources/views/rule/index.php index 7e5e15d..b725b7e 100644 --- a/src/User/resources/views/rule/index.php +++ b/src/User/resources/views/rule/index.php @@ -6,9 +6,9 @@ use yii\helpers\Url; use yii\rbac\Rule; /** - * @var $dataProvider \yii\data\ActiveDataProvider - * @var $searchModel \Da\User\Search\RuleSearch - * @var $this yii\web\View + * @var \yii\data\ActiveDataProvider $dataProvider + * @var \Da\User\Search\RuleSearch $searchModel + * @var yii\web\View $this */ $this->title = Yii::t('usuario', 'Rules'); diff --git a/src/User/resources/views/rule/update.php b/src/User/resources/views/rule/update.php index 2127078..49f65cb 100644 --- a/src/User/resources/views/rule/update.php +++ b/src/User/resources/views/rule/update.php @@ -10,9 +10,9 @@ */ /** + * @var yii\web\View $this * @var \Da\User\Model\Rule $model - * @var $this yii\web\View - * @var $unassignedItems string[] + * @var string[] $unassignedItems */ $this->title = Yii::t('usuario', 'Update rule'); $this->params['breadcrumbs'][] = ['label' => Yii::t('usuario', 'Rules'), 'url' => ['index']]; diff --git a/src/User/resources/views/settings/gdpr-delete.php b/src/User/resources/views/settings/gdpr-delete.php index 5aa0e60..2ed34df 100644 --- a/src/User/resources/views/settings/gdpr-delete.php +++ b/src/User/resources/views/settings/gdpr-delete.php @@ -11,7 +11,7 @@ use yii\widgets\ActiveForm; use yii\helpers\Html; -/* @var $model \Da\User\Form\GdprDeleteForm */ +/** @var \Da\User\Form\GdprDeleteForm $model */ ?>