Skip to content

Commit

Permalink
raise phpstan level = 5 and fix all related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TonisOrmisson committed Feb 27, 2024
1 parent 4c6252f commit 8b65036
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 4
level: 5
paths:
- src
excludePaths:
Expand Down
14 changes: 8 additions & 6 deletions src/User/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,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);
}
Expand Down Expand Up @@ -310,11 +312,11 @@ 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);
Expand Down
2 changes: 2 additions & 0 deletions src/User/Controller/api/v1/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Da\User\Service\UserCreateService;
use Da\User\Traits\ContainerAwareTrait;
use Yii;
use yii\base\Action;
use yii\base\Module;
use yii\db\ActiveRecord;
use yii\filters\Cors;
Expand Down Expand Up @@ -129,6 +130,7 @@ public function behaviors()

/**
* {@inheritdoc}
* @param string|Action $action
*/
public function checkAccess($action, $model = null, $params = [])
{
Expand Down
4 changes: 2 additions & 2 deletions src/User/Search/UserSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ public function search($params)
$userClass = $this->getClassMap()->get(User::class);

if ($this->created_at !== null) {
$date = strtotime($this->created_at);
$date = strtotime((string)$this->created_at);
$query->andFilterWhere(['between', $userClass::tableName().'.created_at', $date, $date + 3600 * 24]);
}

if ($this->last_login_at !== null) {
$date = strtotime($this->last_login_at);
$date = strtotime((string)$this->last_login_at);
$query->andFilterWhere(['between', $userClass::tableName().'.last_login_at', $date, $date + 3600 * 24]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/User/Service/AuthRuleEditionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function run()
return false;
}

/** @var Rule $rule */
/** @var \yii\rbac\Rule $rule */
$rule = $this->make($this->model->className, [], ['name' => $this->model->name]);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public function writeSession($id, $data)
] + $this->condition->currentUserData() + $updatedAt);
if (!$result = $model->save()) {
throw new BaseInvalidArgumentException(
print_r($model->errors, 1)
print_r($model->errors, true)
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/User/Service/TwoFactorEmailCodeGeneratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function run() : string
}
// generate key
$code = random_int(0, 999999);
$code = str_pad($code, 6, 0, STR_PAD_LEFT);
$code = str_pad((string) $code, 6, "0", STR_PAD_LEFT);
// send email
$mailService = MailFactory::makeTwoFactorCodeMailerService($user, $code);
// check the sending emailYii::t(
Expand Down
2 changes: 1 addition & 1 deletion src/User/Service/TwoFactorSmsCodeGeneratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function run()
{
// generate key
$code = random_int(0, 999999);
$code = str_pad($code, 6, 0, STR_PAD_LEFT);
$code = str_pad((string)$code, 6, "0", STR_PAD_LEFT);
// get the mobile phone of the user
$user = $this->user;
$mobilePhone = $user->getAuthTfMobilePhone();
Expand Down
2 changes: 1 addition & 1 deletion src/User/Validator/ReCaptchaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function init()
public function clientValidateAttribute($model, $attribute, $view)
{
$message = addslashes(
$this->notCheckedMessage ?: Yii::t('usuario', '{0} cannot be blank.', $model->getAttributeLabel($attribute))
$this->notCheckedMessage ?: Yii::t('usuario', '{0} cannot be blank.', [$model->getAttributeLabel($attribute)])
);

return "(function(messages){if(!grecaptcha.getResponse()){messages.push('{$message}');}})(messages);";
Expand Down
2 changes: 1 addition & 1 deletion src/User/resources/views/bootstrap5/profile/show.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<?php endif; ?>
<li>
<i class="bi-stopwatch text-muted"></i>
<?= Yii::t('usuario', 'Joined on {0, date}', $profile->user->created_at) ?>
<?= Yii::t('usuario', 'Joined on {0, date}', [$profile->user->created_at]) ?>
</li>
</ul>
<?php if (!empty($profile->bio)): ?>
Expand Down
2 changes: 1 addition & 1 deletion src/User/resources/views/mail/confirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<?= Yii::t('usuario', 'Hello') ?>,
</p>
<p style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 1.6; font-weight: normal; margin: 0 0 10px; padding: 0;">
<?= Yii::t('usuario', 'Thank you for signing up on {0}', Yii::$app->name) ?>.
<?= Yii::t('usuario', 'Thank you for signing up on {0}', [Yii::$app->name]) ?>.
<?= Yii::t('usuario', 'In order to complete your registration, please click the link below') ?>.
</p>
<p style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 1.6; font-weight: normal; margin: 0 0 10px; padding: 0;">
Expand Down
2 changes: 1 addition & 1 deletion src/User/resources/views/mail/reconfirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<?= Yii::t(
'usuario',
'We have received a request to change the email address for your account on {0}',
Yii::$app->name
[Yii::$app->name]
) ?>.
<?= Yii::t('usuario', 'In order to complete your request, please click the link below') ?>.
</p>
Expand Down
2 changes: 1 addition & 1 deletion src/User/resources/views/mail/recovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<?= Yii::t(
'usuario',
'We have received a request to reset the password for your account on {0}',
Yii::$app->name
[Yii::$app->name]
) ?>.
<?= Yii::t('usuario', 'Please click the link below to complete your password reset') ?>.
</p>
Expand Down
2 changes: 1 addition & 1 deletion src/User/resources/views/mail/text/confirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
?>
<?= Yii::t('usuario', 'Hello') ?>,

<?= Yii::t('usuario', 'Thank you for signing up on {0}', Yii::$app->name) ?>.
<?= Yii::t('usuario', 'Thank you for signing up on {0}', [Yii::$app->name]) ?>.
<?= Yii::t('usuario', 'In order to complete your registration, please click the link below') ?>.

<?= $token->url ?>
Expand Down
2 changes: 1 addition & 1 deletion src/User/resources/views/mail/text/reconfirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<?= Yii::t(
'usuario',
'We have received a request to change the email address for your account on {0}',
Yii::$app->name
[Yii::$app->name]
) ?>.
<?= Yii::t('usuario', 'In order to complete your request, please click the link below') ?>.

Expand Down
2 changes: 1 addition & 1 deletion src/User/resources/views/mail/text/recovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
?>
<?= Yii::t('usuario', 'Hello') ?>,

<?= Yii::t('usuario', 'We have received a request to reset the password for your account on {0}', Yii::$app->name) ?>.
<?= Yii::t('usuario', 'We have received a request to reset the password for your account on {0}', [Yii::$app->name]) ?>.
<?= Yii::t('usuario', 'Please click the link below to complete your password reset') ?>.

<?= $token->url ?>
Expand Down
2 changes: 1 addition & 1 deletion src/User/resources/views/mail/text/welcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
?>
<?= Yii::t('usuario', 'Hello') ?>,

<?= Yii::t('usuario', 'Your account on {0} has been created', Yii::$app->name) ?>.
<?= Yii::t('usuario', 'Your account on {0} has been created', [Yii::$app->name]) ?>.
<?php if ($showPassword || $module->generatePasswords): ?>
<?= Yii::t('usuario', 'We have generated a password for you') ?>:
<?= $user->password ?>
Expand Down
2 changes: 1 addition & 1 deletion src/User/resources/views/mail/welcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</p>

<p style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 1.6; font-weight: normal; margin: 0 0 10px; padding: 0;">
<?= Yii::t('usuario', 'Your account on {0} has been created', Yii::$app->name) ?>.
<?= Yii::t('usuario', 'Your account on {0} has been created', [Yii::$app->name]) ?>.
<?php if ($showPassword || $module->generatePasswords): ?>
<?= Yii::t('usuario', 'We have generated a password for you') ?>: <strong><?= Html::encode($user->password) ?></strong>
<?php endif ?>
Expand Down

0 comments on commit 8b65036

Please sign in to comment.