mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Upgrade project to PHP 8.3, add PHPStan, upgrade almost every dependency (#36)
* start updating to PHP 8.3 * taking off! Co-authored-by: ErickSkrauch <erickskrauch@yandex.ru> Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * dropped this Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * migrate to symfonymailer Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * this is so stupid 😭 Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * ah, free, at last. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * oh, Gabriel. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * now dawns thy reckoning. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * and thy gore shall GLISTEN before the temples of man. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * creature of steel. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * my gratitude upon thee for my freedom. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * but the crimes thy kind has committed against humanity Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * Upgrade PHP-CS-Fixer and do fix the codebase * First review round (maybe I have broken something) * are NOT forgotten. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * Enable parallel PHP-CS-Fixer runner * PHPStan level 1 * PHPStan level 2 * PHPStan level 3 * PHPStan level 4 * PHPStan level 5 * Levels 6 and 7 takes too much effort. Generate a baseline and fix them eventually * Resolve TODO's related to the php-mock * Drastically reduce baseline size with the Rector * More code modernization with help of the Rector * Update GitLab CI --------- Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> Co-authored-by: ErickSkrauch <erickskrauch@yandex.ru>
This commit is contained in:
@@ -30,7 +30,7 @@ use const common\LATEST_RULES_VERSION;
|
||||
* @property int|null $rules_agreement_version
|
||||
* @property string|null $registration_ip
|
||||
* @property string|null $otp_secret
|
||||
* @property int $is_otp_enabled
|
||||
* @property bool $is_otp_enabled
|
||||
* @property int $created_at
|
||||
* @property int $updated_at
|
||||
* @property int $password_changed_at
|
||||
@@ -81,16 +81,11 @@ class Account extends ActiveRecord {
|
||||
$passwordHashStrategy = $this->password_hash_strategy;
|
||||
}
|
||||
|
||||
switch ($passwordHashStrategy) {
|
||||
case self::PASS_HASH_STRATEGY_OLD_ELY:
|
||||
return UserPass::make($this->email, $password) === $this->password_hash;
|
||||
|
||||
case self::PASS_HASH_STRATEGY_YII2:
|
||||
return Yii::$app->security->validatePassword($password, $this->password_hash);
|
||||
|
||||
default:
|
||||
throw new InvalidConfigException('You must set valid password_hash_strategy before you can validate password');
|
||||
}
|
||||
return match ($passwordHashStrategy) {
|
||||
self::PASS_HASH_STRATEGY_OLD_ELY => UserPass::make($this->email, $password) === $this->password_hash,
|
||||
self::PASS_HASH_STRATEGY_YII2 => Yii::$app->security->validatePassword($password, $this->password_hash),
|
||||
default => throw new InvalidConfigException('You must set valid password_hash_strategy before you can validate password'),
|
||||
};
|
||||
}
|
||||
|
||||
public function setPassword(string $password): void {
|
||||
@@ -103,6 +98,9 @@ class Account extends ActiveRecord {
|
||||
return $this->hasMany(EmailActivation::class, ['account_id' => 'id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery<\common\models\OauthSession>
|
||||
*/
|
||||
public function getOauthSessions(): ActiveQuery {
|
||||
return $this->hasMany(OauthSession::class, ['account_id' => 'id']);
|
||||
}
|
||||
@@ -116,6 +114,9 @@ class Account extends ActiveRecord {
|
||||
return $this->hasMany(UsernameHistory::class, ['account_id' => 'id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery<\common\models\AccountSession>
|
||||
*/
|
||||
public function getSessions(): ActiveQuery {
|
||||
return $this->hasMany(AccountSession::class, ['account_id' => 'id']);
|
||||
}
|
||||
|
@@ -8,12 +8,12 @@ use yii\db\ActiveRecord;
|
||||
|
||||
/**
|
||||
* Fields:
|
||||
* @property integer $id
|
||||
* @property integer $account_id
|
||||
* @property int $id
|
||||
* @property int $account_id
|
||||
* @property string $refresh_token
|
||||
* @property integer $last_used_ip
|
||||
* @property integer $created_at
|
||||
* @property integer $last_refreshed_at
|
||||
* @property int $last_used_ip
|
||||
* @property int $created_at
|
||||
* @property int $last_refreshed_at
|
||||
*
|
||||
* Relations:
|
||||
* @property Account $account
|
||||
|
@@ -37,6 +37,9 @@ class EmailActivation extends ActiveRecord {
|
||||
return 'email_activations';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<self::TYPE_*, class-string<\common\models\EmailActivation>>
|
||||
*/
|
||||
public static function getClassMap(): array {
|
||||
return [
|
||||
self::TYPE_REGISTRATION_EMAIL_CONFIRMATION => confirmations\RegistrationConfirmation::class,
|
||||
@@ -46,18 +49,16 @@ class EmailActivation extends ActiveRecord {
|
||||
];
|
||||
}
|
||||
|
||||
public static function instantiate($row) {
|
||||
public static function instantiate($row): static {
|
||||
$type = ArrayHelper::getValue($row, 'type');
|
||||
if ($type === null) {
|
||||
return parent::instantiate($row);
|
||||
}
|
||||
|
||||
$classMap = self::getClassMap();
|
||||
if (!isset($classMap[$type])) {
|
||||
throw new InvalidConfigException('Unexpected type');
|
||||
}
|
||||
$className = self::getClassMap()[$type] ?? throw new InvalidConfigException('Unexpected type');
|
||||
|
||||
return new $classMap[$type]();
|
||||
// @phpstan-ignore return.type (the type is correct, but it seems like it must be fixed within Yii2-extension)
|
||||
return new $className();
|
||||
}
|
||||
|
||||
public static function find(): EmailActivationQuery {
|
||||
@@ -72,9 +73,7 @@ class EmailActivation extends ActiveRecord {
|
||||
],
|
||||
[
|
||||
'class' => PrimaryKeyValueBehavior::class,
|
||||
'value' => function(): string {
|
||||
return UserFriendlyRandomKey::make();
|
||||
},
|
||||
'value' => fn(): string => UserFriendlyRandomKey::make(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
@@ -6,9 +6,10 @@ namespace common\models;
|
||||
use yii\db\ActiveQuery;
|
||||
|
||||
/**
|
||||
* @extends \yii\db\ActiveQuery<\common\models\EmailActivation>
|
||||
* @see EmailActivation
|
||||
*/
|
||||
class EmailActivationQuery extends ActiveQuery {
|
||||
final class EmailActivationQuery extends ActiveQuery {
|
||||
|
||||
public function withType(int ...$typeId): self {
|
||||
return $this->andWhere(['type' => $typeId]);
|
||||
|
@@ -11,7 +11,7 @@ use yii\db\Command;
|
||||
*/
|
||||
class OauthClientQuery extends ActiveQuery {
|
||||
|
||||
private $showDeleted = false;
|
||||
private bool $showDeleted = false;
|
||||
|
||||
public function includeDeleted(): self {
|
||||
$this->showDeleted = true;
|
||||
|
@@ -10,12 +10,9 @@ use Yii;
|
||||
|
||||
class Textures {
|
||||
|
||||
private const MAX_RETRIES = 3;
|
||||
private const int MAX_RETRIES = 3;
|
||||
|
||||
protected Account $account;
|
||||
|
||||
public function __construct(Account $account) {
|
||||
$this->account = $account;
|
||||
public function __construct(protected Account $account) {
|
||||
}
|
||||
|
||||
public function getMinecraftResponse(bool $signed = false): array {
|
||||
|
Reference in New Issue
Block a user