-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #541 from TonisOrmisson/phpstan-levelup
V2: Static code analysis phpstan level raised 0=>5 with fixes
- Loading branch information
Showing
63 changed files
with
263 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
parameters: | ||
level: 1 | ||
level: 5 | ||
paths: | ||
- src | ||
excludePaths: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,12 @@ | |
use Da\User\Contracts\AuthManagerInterface; | ||
use Da\User\Controller\SecurityController; | ||
use Da\User\Event\FormEvent; | ||
use Da\User\Form\LoginForm; | ||
use Da\User\Helper\ClassMapHelper; | ||
use Da\User\Model\SessionHistory; | ||
use Da\User\Model\User; | ||
use Da\User\Search\SessionHistorySearch; | ||
use Da\User\Traits\ModuleAwareTrait; | ||
use Yii; | ||
use yii\authclient\Collection; | ||
use yii\base\Application; | ||
|
@@ -37,6 +39,8 @@ | |
*/ | ||
class Bootstrap implements BootstrapInterface | ||
{ | ||
use ModuleAwareTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
|
@@ -57,7 +61,9 @@ public function bootstrap($app) | |
$this->initAuthCollection($app); | ||
$this->initAuthManager($app); | ||
} else { | ||
/* @var $app ConsoleApplication */ | ||
if(!($app instanceof ConsoleApplication)) { | ||
throw new InvalidConfigException(); | ||
} | ||
$this->initConsoleCommands($app); | ||
$this->initAuthManager($app); | ||
} | ||
|
@@ -155,10 +161,12 @@ function () use ($model) { | |
} | ||
|
||
// Attach an event to check if the password has expired | ||
if (null !== Yii::$app->getModule('user')->maxPasswordAge) { | ||
if (null !== $this->getModule()->maxPasswordAge) { | ||
YiiEvent::on(SecurityController::class, FormEvent::EVENT_AFTER_LOGIN, function (FormEvent $event) { | ||
$user = $event->form->user; | ||
if ($user->password_age >= Yii::$app->getModule('user')->maxPasswordAge) { | ||
/** @var LoginForm $form */ | ||
$form = $event->form; | ||
$user = $form->getUser(); | ||
if ($user->password_age >= $this->getModule()->maxPasswordAge) { | ||
// Force password change | ||
Yii::$app->session->setFlash('warning', Yii::t('usuario', 'Your password has expired, you must change it now')); | ||
Yii::$app->response->redirect(['/user/settings/account'])->send(); | ||
|
@@ -195,17 +203,17 @@ function () use ($model) { | |
] | ||
]; | ||
|
||
$app->getModule('user')->twoFactorAuthenticationValidators = ArrayHelper::merge( | ||
$this->getModule()->twoFactorAuthenticationValidators = ArrayHelper::merge( | ||
$defaultTwoFactorAuthenticationValidators, | ||
$app->getModule('user')->twoFactorAuthenticationValidators | ||
$this->getModule()->twoFactorAuthenticationValidators | ||
); | ||
|
||
if ($app instanceof WebApplication) { | ||
// override Yii | ||
$di->set( | ||
'yii\web\User', | ||
[ | ||
'enableAutoLogin' => $app->getModule('user')->enableAutoLogin, | ||
'enableAutoLogin' => $this->getModule()->enableAutoLogin, | ||
'loginUrl' => ['/user/security/login'], | ||
'identityClass' => $di->get(ClassMapHelper::class)->get(User::class), | ||
] | ||
|
@@ -262,8 +270,7 @@ protected function initAuthManager(Application $app) | |
*/ | ||
protected function initUrlRoutes(WebApplication $app) | ||
{ | ||
/** @var $module Module */ | ||
$module = $app->getModule('user'); | ||
$module = $this->getModule(); | ||
$config = [ | ||
'class' => 'yii\web\GroupUrlRule', | ||
'prefix' => $module->prefix, | ||
|
@@ -300,19 +307,16 @@ protected function initUrlRestRoutes(WebApplication $app) | |
|
||
/** | ||
* Ensures required mail parameters needed for the mail service. | ||
* | ||
* @param Application $app | ||
* @param Module|\yii\base\Module $module | ||
*/ | ||
protected function initMailServiceConfiguration(Application $app, Module $module) | ||
{ | ||
$defaults = [ | ||
'fromEmail' => '[email protected]', | ||
'welcomeMailSubject' => Yii::t('usuario', 'Welcome to {0}', $app->name), | ||
'confirmationMailSubject' => Yii::t('usuario', 'Confirm account on {0}', $app->name), | ||
'reconfirmationMailSubject' => Yii::t('usuario', 'Confirm email change on {0}', $app->name), | ||
'recoveryMailSubject' => Yii::t('usuario', 'Complete password reset on {0}', $app->name), | ||
'twoFactorMailSubject' => Yii::t('usuario', 'Code for two factor authentication on {0}', $app->name), | ||
'welcomeMailSubject' => Yii::t('usuario', 'Welcome to {0}', [$app->name]), | ||
'confirmationMailSubject' => Yii::t('usuario', 'Confirm account on {0}', [$app->name]), | ||
'reconfirmationMailSubject' => Yii::t('usuario', 'Confirm email change on {0}', [$app->name]), | ||
'recoveryMailSubject' => Yii::t('usuario', 'Complete password reset on {0}', [$app->name]), | ||
'twoFactorMailSubject' => Yii::t('usuario', 'Code for two factor authentication on {0}', [$app->name]), | ||
]; | ||
|
||
$module->mailParams = array_merge($defaults, $module->mailParams); | ||
|
@@ -339,7 +343,7 @@ protected function initAuthCollection(WebApplication $app) | |
*/ | ||
protected function initConsoleCommands(ConsoleApplication $app) | ||
{ | ||
$app->getModule('user')->controllerNamespace = $app->getModule('user')->consoleControllerNamespace; | ||
$this->getModule()->controllerNamespace = $this->getModule()->consoleControllerNamespace; | ||
} | ||
|
||
/** | ||
|
@@ -349,7 +353,6 @@ protected function initConsoleCommands(ConsoleApplication $app) | |
*/ | ||
protected function initControllerNamespace(WebApplication $app) | ||
{ | ||
$app->getModule('user')->controllerNamespace = $app->getModule('user')->controllerNamespace; | ||
$app->getModule('user')->setViewPath($app->getModule('user')->viewPath); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.