Merge pull request #464 from TonisOrmisson/static-code-analyzer
Static code analyzer
This commit is contained in:
3
.github/workflows/php.yml
vendored
3
.github/workflows/php.yml
vendored
@ -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()
|
||||
|
||||
@ -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"
|
||||
},
|
||||
|
||||
8
phpstan.neon
Normal file
8
phpstan.neon
Normal file
@ -0,0 +1,8 @@
|
||||
parameters:
|
||||
level: 1
|
||||
paths:
|
||||
- src
|
||||
excludePaths:
|
||||
- 'src/resources/i18n/*'
|
||||
bootstrapFiles:
|
||||
- stan_autoload.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';
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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]);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 */
|
||||
|
||||
?>
|
||||
|
||||
|
||||
@ -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 */
|
||||
|
||||
?>
|
||||
|
||||
|
||||
@ -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 */
|
||||
|
||||
?>
|
||||
|
||||
<?php $this->beginContent('@Da/User/resources/views/admin/update.php', ['user' => $user]) ?>
|
||||
|
||||
@ -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
|
||||
*/
|
||||
?>
|
||||
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -10,8 +10,8 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var \yii\web\View
|
||||
* @var yii\mail\BaseMessage $content
|
||||
* @var \yii\web\View $this
|
||||
* @var string $content
|
||||
*/
|
||||
?>
|
||||
<?php $this->beginPage() ?>
|
||||
|
||||
@ -10,7 +10,9 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var string main view render result
|
||||
/**
|
||||
* @var \yii\web\View $this
|
||||
* @var string $content
|
||||
*/
|
||||
?>
|
||||
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var \Da\User\Model\User
|
||||
* @var \Da\User\Model\Token $token
|
||||
*/
|
||||
?>
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var \Da\User\Model\Token
|
||||
* @var \Da\User\Model\Token $token
|
||||
*/
|
||||
?>
|
||||
<?= Yii::t('usuario', 'Hello') ?>,
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var \Da\User\Model\User
|
||||
* @var \Da\User\Model\Token $token
|
||||
*/
|
||||
?>
|
||||
|
||||
@ -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') ?>,
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
) ?>
|
||||
|
||||
<?php $this->endContent() ?>
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var $this yii\web\View
|
||||
* @var $model \Da\User\Model\Rule
|
||||
* @var yii\web\View $this
|
||||
* @var \Da\User\Model\Rule $model
|
||||
*/
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
@ -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', 'Create new rule');
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -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']];
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
use yii\widgets\ActiveForm;
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $model \Da\User\Form\GdprDeleteForm */
|
||||
/** @var \Da\User\Form\GdprDeleteForm $model */
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $module \Da\User\Module */
|
||||
/** @var \yii\web\View $this */
|
||||
/** @var \Da\User\Module $module */
|
||||
|
||||
$this->title = Yii::t('usuario', 'Privacy settings');
|
||||
|
||||
|
||||
@ -11,9 +11,8 @@
|
||||
|
||||
use yii\bootstrap\Alert;
|
||||
|
||||
/**
|
||||
* @var $module Da\User\Module
|
||||
*/
|
||||
/** @var \Da\User\Module $module */
|
||||
|
||||
?>
|
||||
|
||||
<?php if ($module->enableFlashMessages): ?>
|
||||
|
||||
@ -11,9 +11,8 @@
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/**
|
||||
* @var $content string
|
||||
*/
|
||||
/** @var \yii\web\View $this */
|
||||
/** @var string $content */
|
||||
|
||||
?>
|
||||
<div class="clearfix"></div>
|
||||
|
||||
@ -9,11 +9,11 @@
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var yii\web\View
|
||||
* @var \Da\User\Module $module
|
||||
* @var string $title
|
||||
*/
|
||||
/** @var \yii\web\View $this */
|
||||
/** @var string $content */
|
||||
/** @var string $title */
|
||||
/** @var \Da\User\Module $module */
|
||||
|
||||
|
||||
$this->title = $title;
|
||||
|
||||
|
||||
@ -14,11 +14,10 @@ use yii\bootstrap\Alert;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/**
|
||||
* @var $this yii\web\View
|
||||
* @var $model Da\User\Model\Assignment
|
||||
* @var $availableItems string[]
|
||||
*/
|
||||
/** @var \yii\web\View $this */
|
||||
/** @var string[] $availableItems */
|
||||
/** @var Da\User\Model\Assignment $model */
|
||||
|
||||
|
||||
?>
|
||||
|
||||
|
||||
4
stan_autoload.php
Normal file
4
stan_autoload.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
// PHPStan fails to autoload Yii somehow
|
||||
include 'vendor/yiisoft/yii2/Yii.php';
|
||||
Reference in New Issue
Block a user