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:
Octol1ttle
2024-12-02 15:10:55 +05:00
committed by GitHub
parent 625250b367
commit 57d492da8a
356 changed files with 10531 additions and 4761 deletions

View File

@@ -3,7 +3,7 @@ actor_suffix: Tester
bootstrap: _bootstrap.php
paths:
tests: tests
log: tests/_output
output: tests/_output
data: tests/_data
helpers: tests/_support
settings:

View File

@@ -8,7 +8,7 @@ return [
'log' => [
'targets' => [
[
'class' => mito\sentry\Target::class,
'class' => nohnaimer\sentry\Target::class,
'levels' => ['error', 'warning'],
],
[

View File

@@ -12,15 +12,8 @@ use yii\console\ExitCode;
class CleanupController extends Controller {
public function actionEmailKeys(): int {
$query = EmailActivation::find();
foreach ($this->getEmailActivationsDurationsMap() as $typeId => $expiration) {
$query->orWhere([
'AND',
['type' => $typeId],
['<', 'created_at', time() - $expiration],
]);
}
$query = EmailActivation::find()
->andWhere(['<', 'created_at', time() - 60 * 60 * 24 * 14]); // 14d
foreach ($query->each(100, Yii::$app->unbufferedDb) as $email) {
/** @var EmailActivation $email */
$email->delete();
@@ -68,21 +61,4 @@ class CleanupController extends Controller {
return ExitCode::OK;
}
private function getEmailActivationsDurationsMap(): array {
$durationsMap = [];
foreach (EmailActivation::getClassMap() as $typeId => $className) {
/** @var EmailActivation $object */
$object = new $className();
/** @var \common\behaviors\EmailActivationExpirationBehavior $behavior */
$behavior = $object->getBehavior('expirationBehavior');
/** @noinspection NullPointerExceptionInspection */
$expiration = $behavior->expirationTimeout ?? 1123200; // 13d by default
// We increment 1 day so that users can still receive notifications about the expiry of the activation code
/** @noinspection SummerTimeUnsafeTimeManipulationInspection */
$durationsMap[$typeId] = $expiration + 86400;
}
return $durationsMap;
}
}

View File

@@ -20,9 +20,7 @@ class ManualMigrateController extends Controller {
$cursor = (int)$response[0];
$keys = $response[1];
if (!empty($keys)) {
$sessionsIds = array_map(function(string $key): int {
return (int)explode(':', $key)[2];
}, $keys);
$sessionsIds = array_map(fn(string $key): int => (int)explode(':', $key)[2], $keys);
/** @var OauthSession[] $sessions */
$sessions = OauthSession::find()->andWhere(['legacy_id' => $sessionsIds])->all();
foreach ($sessions as $session) {

View File

@@ -5,10 +5,11 @@ use yii\db\Migration as YiiMigration;
/**
* @property string $tableOptions
* @method \SamIT\Yii2\MariaDb\ColumnSchemaBuilder json()
*/
class Migration extends YiiMigration {
public function getTableOptions($engine = 'InnoDB') {
public function getTableOptions(string $engine = 'InnoDB'): string {
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=' . $engine;
@@ -17,7 +18,7 @@ class Migration extends YiiMigration {
return $tableOptions;
}
public function createTable($table, $columns, $options = null) {
public function createTable($table, $columns, $options = null): void {
if ($options === null) {
$options = $this->getTableOptions();
}

View File

@@ -4,7 +4,7 @@ use console\db\Migration;
class m130524_201442_init extends Migration {
public function up() {
public function up(): void {
$this->createTable('{{%accounts}}', [
'id' => $this->primaryKey(),
'uuid' => $this->string(36)->notNull(),
@@ -19,7 +19,7 @@ class m130524_201442_init extends Migration {
], $this->tableOptions);
}
public function down() {
public function down(): void {
$this->dropTable('{{%accounts}}');
}

View File

@@ -4,11 +4,11 @@ use console\db\Migration;
class m160104_150157_account_extended_info extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->addColumn('{{%accounts}}', 'username', $this->string()->unique()->notNull() . ' AFTER `uuid`');
}
public function safeDown() {
public function safeDown(): void {
$this->dropColumn('{{%accounts}}', 'username');
}

View File

@@ -4,7 +4,7 @@ use console\db\Migration;
class m160114_134716_account_email_keys extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->createTable('{{%email_activations}}', [
'id' => $this->primaryKey(),
'account_id' => $this->getDb()->getTableSchema('{{%accounts}}')->getColumn('id')->dbType . ' NOT NULL',
@@ -16,7 +16,7 @@ class m160114_134716_account_email_keys extends Migration {
$this->addForeignKey('FK_email_activation_to_account', '{{%email_activations}}', 'account_id', '{{%accounts}}', 'id', 'CASCADE', 'CASCADE');
}
public function safeDown() {
public function safeDown(): void {
$this->dropTable('{{%email_activations}}');
}

View File

@@ -4,14 +4,14 @@ use console\db\Migration;
class m160118_184027_email_activations_code_as_primary_key extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->dropColumn('{{%email_activations}}', 'id');
$this->dropIndex('key', '{{%email_activations}}');
$this->alterColumn('{{%email_activations}}', 'key', $this->string()->notNull() . ' FIRST');
$this->addPrimaryKey('key', '{{%email_activations}}', 'key');
}
public function safeDown() {
public function safeDown(): void {
$this->dropPrimaryKey('key', '{{%email_activations}}');
$this->addColumn('{{%email_activations}}', 'id', $this->primaryKey() . ' FIRST');
$this->alterColumn('{{%email_activations}}', 'key', $this->string()->unique()->notNull() . ' AFTER `id`');

View File

@@ -4,7 +4,7 @@ use console\db\Migration;
class m160201_055928_oauth extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->createTable('{{%oauth_clients}}', [
'id' => $this->string(64),
'secret' => $this->string()->notNull(),
@@ -43,7 +43,7 @@ class m160201_055928_oauth extends Migration {
'account_id',
'{{%accounts}}',
'id',
'CASCADE'
'CASCADE',
);
$this->addForeignKey(
@@ -53,7 +53,7 @@ class m160201_055928_oauth extends Migration {
'{{%oauth_clients}}',
'id',
'CASCADE',
'CASCADE'
'CASCADE',
);
$this->addForeignKey(
@@ -63,11 +63,11 @@ class m160201_055928_oauth extends Migration {
'{{%oauth_sessions}}',
'id',
'CASCADE',
'SET NULL'
'SET NULL',
);
}
public function safeDown() {
public function safeDown(): void {
$this->dropTable('{{%oauth_access_tokens}}');
$this->dropTable('{{%oauth_sessions}}');
$this->dropTable('{{%oauth_scopes}}');

View File

@@ -4,14 +4,14 @@ use console\db\Migration;
class m160222_204006_add_init_scopes extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->batchInsert('{{%oauth_scopes}}', ['id'], [
['offline_access'],
['minecraft_server_session'],
]);
}
public function safeDown() {
public function safeDown(): void {
$this->delete('{{%oauth_scopes}}');
}

View File

@@ -4,7 +4,7 @@ use console\db\Migration;
class m160311_211107_password_change_time extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->addColumn('{{%accounts}}', 'password_changed_at', $this->integer()->notNull());
$this->getDb()->createCommand('
UPDATE {{%accounts}}
@@ -13,7 +13,7 @@ class m160311_211107_password_change_time extends Migration {
$this->dropColumn('{{%accounts}}', 'auth_key');
}
public function safeDown() {
public function safeDown(): void {
$this->dropColumn('{{%accounts}}', 'password_changed_at');
$this->addColumn('{{%accounts}}', 'auth_key', $this->string(32)->notNull() . ' AFTER `status`');
}

View File

@@ -4,7 +4,7 @@ use console\db\Migration;
class m160414_231110_account_nicknames_history extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->createTable('{{%usernames_history}}', [
'id' => $this->primaryKey(),
'username' => $this->string()->notNull(),
@@ -30,7 +30,7 @@ class m160414_231110_account_nicknames_history extends Migration {
}
}
public function safeDown() {
public function safeDown(): void {
$this->dropTable('{{%usernames_history}}');
}

View File

@@ -4,7 +4,7 @@ use console\db\Migration;
class m160422_230911_mojang_account_collisions extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->createTable('{{%mojang_usernames}}', [
'username' => $this->string()->notNull(),
'uuid' => $this->string(32)->notNull(),
@@ -14,7 +14,7 @@ class m160422_230911_mojang_account_collisions extends Migration {
$this->addPrimaryKey('username', '{{%mojang_usernames}}', 'username');
}
public function safeDown() {
public function safeDown(): void {
$this->dropTable('{{%mojang_usernames}}');
}

View File

@@ -4,14 +4,14 @@ use console\db\Migration;
class m160512_080955_usernames_history_encoding extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->getDb()->createCommand('
ALTER TABLE {{%usernames_history}}
MODIFY username VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
')->execute();
}
public function safeDown() {
public function safeDown(): void {
$this->alterColumn('{{%usernames_history}}', 'username', $this->string()->notNull());
}

View File

@@ -4,12 +4,12 @@ use console\db\Migration;
class m160512_194546_account_language extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->addColumn('{{%accounts}}', 'lang', $this->string(5)->notNull()->defaultValue('en')->after('password_hash_strategy'));
$this->dropColumn('{{%accounts}}', 'password_reset_token');
}
public function safeDown() {
public function safeDown(): void {
$this->dropColumn('{{%accounts}}', 'lang');
$this->addColumn('{{%accounts}}', 'password_reset_token', $this->string()->unique());
}

View File

@@ -4,11 +4,11 @@ use console\db\Migration;
class m160515_153724_email_activation_data extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->addColumn('{{%email_activations}}', '_data', $this->text()->after('type'));
}
public function safeDown() {
public function safeDown(): void {
$this->dropColumn('{{%email_activations}}', '_data');
}

View File

@@ -4,7 +4,7 @@ use console\db\Migration;
class m160517_151805_account_sessions extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->createTable('{{%accounts_sessions}}', [
'id' => $this->primaryKey(),
'account_id' => $this->db->getTableSchema('{{%accounts}}')->getColumn('id')->dbType . ' NOT NULL',
@@ -17,7 +17,7 @@ class m160517_151805_account_sessions extends Migration {
$this->addForeignKey('FK_account_session_to_account', '{{%accounts_sessions}}', 'account_id', '{{%accounts}}', 'id', 'CASCADE', 'CASCADE');
}
public function safeDown() {
public function safeDown(): void {
$this->dropTable('{{%accounts_sessions}}');
}

View File

@@ -4,14 +4,14 @@ use console\db\Migration;
class m160803_185857_account_permissions extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->batchInsert('{{%oauth_scopes}}', ['id'], [
['account_info'],
['account_email'],
]);
}
public function safeDown() {
public function safeDown(): void {
$this->delete('{{%oauth_scopes}}', ['id' => ['account_info', 'account_email']]);
}

View File

@@ -4,11 +4,11 @@ use console\db\Migration;
class m160806_144759_account_rules_agreement_version extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->addColumn('{{%accounts}}', 'rules_agreement_version', $this->smallInteger()->unsigned()->after('status'));
}
public function safeDown() {
public function safeDown(): void {
$this->dropColumn('{{%accounts}}', 'rules_agreement_version');
}

View File

@@ -4,7 +4,7 @@ use console\db\Migration;
class m160808_191142_ely_by_app extends Migration {
public function safeUp() {
public function safeUp(): void {
$exists = $this->db->createCommand('
SELECT COUNT(*)
FROM {{%oauth_clients}}
@@ -25,7 +25,7 @@ class m160808_191142_ely_by_app extends Migration {
}
}
public function safeDown() {
public function safeDown(): void {
$this->delete('{{%oauth_clients}}', ['id' => 'ely']);
}

View File

@@ -4,11 +4,11 @@ use console\db\Migration;
class m160817_225019_registration_ip extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->addColumn('{{%accounts}}', 'registration_ip', 'VARBINARY(16) AFTER rules_agreement_version');
}
public function safeDown() {
public function safeDown(): void {
$this->dropColumn('{{%accounts}}', 'registration_ip');
}

View File

@@ -4,7 +4,7 @@ use console\db\Migration;
class m160819_211139_minecraft_access_tokens extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->createTable('{{%minecraft_access_keys}}', [
'access_token' => $this->string(36)->notNull(),
'client_token' => $this->string(36)->notNull(),
@@ -18,7 +18,7 @@ class m160819_211139_minecraft_access_tokens extends Migration {
$this->createIndex('client_token', '{{%minecraft_access_keys}}', 'client_token', true);
}
public function safeDown() {
public function safeDown(): void {
$this->dropTable('{{%minecraft_access_keys}}');
}

View File

@@ -4,7 +4,7 @@ use console\db\Migration;
class m160919_170008_improve_username_history extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->execute('
INSERT INTO {{%usernames_history}} (account_id, username, applied_in)
SELECT id as account_id, username, created_at as applied_at
@@ -14,7 +14,7 @@ class m160919_170008_improve_username_history extends Migration {
$this->createIndex('username', '{{%usernames_history}}', 'username');
}
public function safeDown() {
public function safeDown(): void {
$this->dropIndex('applied_in', '{{%usernames_history}}');
$this->dropIndex('username', '{{%usernames_history}}');
$this->execute('

View File

@@ -4,11 +4,11 @@ use console\db\Migration;
class m161024_234121_remove_client_token_index extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->dropIndex('client_token', '{{%minecraft_access_keys}}');
}
public function safeDown() {
public function safeDown(): void {
$this->createIndex('client_token', '{{%minecraft_access_keys}}', 'client_token', true);
}

View File

@@ -4,7 +4,7 @@ use console\db\Migration;
class m161030_013122_ely_by_admin_app extends Migration {
public function safeUp() {
public function safeUp(): void {
$exists = $this->db->createCommand('
SELECT COUNT(*)
FROM {{%oauth_clients}}
@@ -27,7 +27,7 @@ class m161030_013122_ely_by_admin_app extends Migration {
}
}
public function safeDown() {
public function safeDown(): void {
$this->delete('{{%oauth_clients}}', ['id' => 'ely_admin']);
}

View File

@@ -4,11 +4,11 @@ use console\db\Migration;
class m161104_150634_accounts_uuid_index extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->createIndex('uuid', '{{%accounts}}', 'uuid', true);
}
public function safeDown() {
public function safeDown(): void {
$this->dropColumn('{{%accounts}}', 'uuid');
}

View File

@@ -4,11 +4,11 @@ use console\db\Migration;
class m161127_145211_remove_oauth_scopes extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->dropTable('{{%oauth_scopes}}');
}
public function safeDown() {
public function safeDown(): void {
$this->createTable('{{%oauth_scopes}}', [
'id' => $this->string(64),
$this->primary('id'),

View File

@@ -4,12 +4,12 @@ use console\db\Migration;
class m161222_222520_remove_oauth_access_tokens extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->dropForeignKey('FK_oauth_access_toke_to_oauth_session', '{{%oauth_access_tokens}}');
$this->dropTable('{{%oauth_access_tokens}}');
}
public function safeDown() {
public function safeDown(): void {
$this->createTable('{{%oauth_access_tokens}}', [
'access_token' => $this->string(64),
'session_id' => $this->getDb()->getTableSchema('{{%oauth_sessions}}')->getColumn('id')->dbType,
@@ -24,7 +24,7 @@ class m161222_222520_remove_oauth_access_tokens extends Migration {
'{{%oauth_sessions}}',
'id',
'CASCADE',
'SET NULL'
'SET NULL',
);
}

View File

@@ -4,11 +4,11 @@ use console\db\Migration;
class m161228_101022_oauth_clients_allow_null_redirect_uri extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->alterColumn('{{%oauth_clients}}', 'redirect_uri', $this->string());
}
public function safeDown() {
public function safeDown(): void {
$this->alterColumn('{{%oauth_clients}}', 'redirect_uri', $this->string()->notNull());
}

View File

@@ -4,12 +4,12 @@ use console\db\Migration;
class m170118_224937_account_otp_secrets extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->addColumn('{{%accounts}}', 'otp_secret', $this->string()->after('registration_ip'));
$this->addColumn('{{%accounts}}', 'is_otp_enabled', $this->boolean()->notNull()->defaultValue(false)->after('otp_secret'));
}
public function safeDown() {
public function safeDown(): void {
$this->dropColumn('{{%accounts}}', 'otp_secret');
$this->dropColumn('{{%accounts}}', 'is_otp_enabled');
}

View File

@@ -4,11 +4,11 @@ use console\db\Migration;
class m170415_195802_oauth_sessions_owner_id_index extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->createIndex('owner_id', '{{%oauth_sessions}}', 'owner_id');
}
public function safeDown() {
public function safeDown(): void {
$this->dropIndex('owner_id', '{{%oauth_sessions}}');
}

View File

@@ -4,11 +4,11 @@ use console\db\Migration;
class m170704_215436_allow_null_owner_id extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->alterColumn('{{%oauth_sessions}}', 'owner_id', $this->string()->null());
}
public function safeDown() {
public function safeDown(): void {
$this->delete('{{%oauth_sessions}}', ['owner_id' => null]);
$this->alterColumn('{{%oauth_sessions}}', 'owner_id', $this->string()->notNull());
}

View File

@@ -4,7 +4,7 @@ use console\db\Migration;
class m171222_200114_migrate_to_utf8md4_unicode_ci extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->execute('SET FOREIGN_KEY_CHECKS=0');
$dbName = $this->db->createCommand('SELECT DATABASE()')->queryScalar();
@@ -19,7 +19,7 @@ class m171222_200114_migrate_to_utf8md4_unicode_ci extends Migration {
$this->execute('SET FOREIGN_KEY_CHECKS=1');
}
public function safeDown() {
public function safeDown(): void {
$this->execute('SET FOREIGN_KEY_CHECKS=0');
$dbName = $this->db->createCommand('SELECT DATABASE()')->queryScalar();

View File

@@ -4,11 +4,11 @@ use console\db\Migration;
class m180102_164624_increase_minecraft_access_keys_client_token_length extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->alterColumn('{{%minecraft_access_keys}}', 'client_token', $this->string()->notNull());
}
public function safeDown() {
public function safeDown(): void {
$this->alterColumn('{{%minecraft_access_keys}}', 'client_token', $this->string(36)->notNull());
}

View File

@@ -4,7 +4,7 @@ use console\db\Migration;
class m180224_132027_extend_oauth_clients_attributes extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->addColumn('{{%oauth_clients}}', 'type', $this->string()->notNull()->after('secret'));
$this->addColumn('{{%oauth_clients}}', 'website_url', $this->string()->null()->after('redirect_uri'));
$this->addColumn('{{%oauth_clients}}', 'minecraft_server_ip', $this->string()->null()->after('website_url'));
@@ -18,7 +18,7 @@ class m180224_132027_extend_oauth_clients_attributes extends Migration {
]);
}
public function safeDown() {
public function safeDown(): void {
$this->dropColumn('{{%oauth_clients}}', 'type');
$this->dropColumn('{{%oauth_clients}}', 'website_url');
$this->dropColumn('{{%oauth_clients}}', 'minecraft_server_ip');

View File

@@ -4,7 +4,7 @@ use console\db\Migration;
class m180706_230451_webhooks extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->createTable('{{%webhooks}}', [
'id' => $this->primaryKey(11)->unsigned(),
'url' => $this->string()->notNull(),
@@ -20,7 +20,7 @@ class m180706_230451_webhooks extends Migration {
$this->addForeignKey('FK_webhook_event_to_webhook', '{{%webhooks_events}}', 'webhook_id', 'webhooks', 'id', 'CASCADE', 'CASCADE');
}
public function safeDown() {
public function safeDown(): void {
$this->dropTable('{{%webhooks_events}}');
$this->dropTable('{{%webhooks}}');
}

View File

@@ -4,11 +4,11 @@ use console\db\Migration;
class m180708_155425_extends_locale_field extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->alterColumn('{{%accounts}}', 'lang', $this->string()->notNull()->defaultValue('en'));
}
public function safeDown() {
public function safeDown(): void {
$this->alterColumn('{{%accounts}}', 'lang', $this->string(5)->notNull()->defaultValue('en'));
}

View File

@@ -5,7 +5,7 @@ use console\db\Migration;
class m190914_181236_rework_oauth_related_tables extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->delete('oauth_sessions', ['NOT', ['owner_type' => 'user']]);
$this->dropColumn('oauth_sessions', 'owner_type');
$this->dropColumn('oauth_sessions', 'client_redirect_uri');
@@ -45,7 +45,7 @@ class m190914_181236_rework_oauth_related_tables extends Migration {
]);
}
public function safeDown() {
public function safeDown(): void {
$this->delete('oauth_clients', ['id' => 'unauthorized_minecraft_game_launcher']);
$this->dropColumn('oauth_sessions', 'revoked_at');

View File

@@ -5,7 +5,7 @@ use yii\db\Expression;
class m191220_214310_rework_email_activations_data_column extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->addColumn('email_activations', 'data', $this->json()->toString('data') . ' AFTER `_data`');
$rows = $this->db->createCommand('
SELECT `key`, `_data`
@@ -23,7 +23,7 @@ class m191220_214310_rework_email_activations_data_column extends Migration {
$this->dropColumn('email_activations', '_data');
}
public function safeDown() {
public function safeDown(): void {
$this->addColumn('email_activations', '_data', $this->text()->after('type'));
$rows = $this->db->createCommand('
SELECT `key`, `data`
@@ -32,7 +32,7 @@ class m191220_214310_rework_email_activations_data_column extends Migration {
')->queryAll();
foreach ($rows as $row) {
$this->update('email_activations', [
'_data' => serialize(json_decode($row['data'], true)),
'_data' => serialize(json_decode((string)$row['data'], true)),
], [
'key' => $row['key'],
]);

View File

@@ -4,11 +4,11 @@ use console\db\Migration;
class m200611_123017_accounts_deletion extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->addColumn('accounts', 'deleted_at', $this->integer(11)->unsigned());
}
public function safeDown() {
public function safeDown(): void {
$this->dropColumn('accounts', 'deleted_at');
}

View File

@@ -4,7 +4,7 @@ use console\db\Migration;
class m200613_204832_remove_webhooks_events_table extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->addColumn('webhooks', 'events', $this->json()->toString('events') . ' AFTER `secret`');
$webhooksIds = $this->db->createCommand('SELECT id FROM webhooks')->queryColumn();
foreach ($webhooksIds as $webhookId) {
@@ -19,7 +19,7 @@ class m200613_204832_remove_webhooks_events_table extends Migration {
$this->dropTable('webhooks_events');
}
public function safeDown() {
public function safeDown(): void {
$this->createTable('webhooks_events', [
'webhook_id' => $this->db->getTableSchema('webhooks')->getColumn('id')->dbType . ' NOT NULL',
'event_type' => $this->string()->notNull(),
@@ -33,7 +33,7 @@ class m200613_204832_remove_webhooks_events_table extends Migration {
continue;
}
$events = json_decode($webhook['events'], true);
$events = json_decode((string)$webhook['events'], true);
if (empty($events)) {
continue;
}
@@ -41,7 +41,7 @@ class m200613_204832_remove_webhooks_events_table extends Migration {
$this->batchInsert(
'webhooks_events',
['webhook_id', 'event_type'],
array_map(fn($event) => [$webhook['id'], $event], $events),
array_map(fn($event): array => [$webhook['id'], $event], $events),
);
}

View File

@@ -5,14 +5,14 @@ use yii\db\Expression;
class m200925_224423_add_oauth_sessions_last_used_at_column extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->addColumn('oauth_sessions', 'last_used_at', $this->integer(11)->unsigned()->notNull());
$this->update('oauth_sessions', [
'last_used_at' => new Expression('`created_at`'),
]);
}
public function safeDown() {
public function safeDown(): void {
$this->dropColumn('oauth_sessions', 'last_used_at');
}

View File

@@ -5,11 +5,11 @@ use console\db\Migration;
class m240614_024554_drop_minecraft_access_keys_table extends Migration {
public function safeUp() {
public function safeUp(): void {
$this->dropTable('minecraft_access_keys');
}
public function safeDown() {
public function safeDown(): void {
$this->createTable('minecraft_access_keys', [
'access_token' => $this->string(36)->notNull(),
'client_token' => $this->string()->notNull(),

View File

@@ -10,20 +10,23 @@ use yii\base\Model;
class WebHookForm extends Model {
public $url;
public string $url;
public $secret;
public string $secret;
public $events = [];
/**
* @var string[]
*/
public array $events = [];
private $webHook;
public function __construct(WebHook $webHook, array $config = []) {
public function __construct(
private WebHook $webHook,
array $config = [],
) {
parent::__construct($config);
$this->webHook = $webHook;
$this->url = $webHook->url;
$this->secret = $webHook->secret;
$this->events = (array)$webHook->events;
$this->url = $this->webHook->url;
$this->secret = $this->webHook->secret;
$this->events = $this->webHook->events;
}
public function rules(): array {

View File

@@ -4,5 +4,4 @@ use common\config\ConfigLoader;
use yii\helpers\ArrayHelper;
return ArrayHelper::merge(ConfigLoader::load('console'), [
]);

View File

@@ -1,4 +1,5 @@
class_name: UnitTester
suite_namespace: console\tests\unit
actor: UnitTester
modules:
enabled:
- Yii2:

View File

@@ -3,12 +3,15 @@ declare(strict_types=1);
namespace console\tests\unit;
use AllowDynamicProperties;
use Codeception\Test\Unit;
use common\tests\helpers\ExtendedPHPMock;
use console\tests\UnitTester;
/**
* @property \console\tests\UnitTester $tester
* @property UnitTester $tester
*/
#[AllowDynamicProperties]
class TestCase extends Unit {
use ExtendedPHPMock;

View File

@@ -23,7 +23,7 @@ class CleanupControllerTest extends TestCase {
];
}
public function testActionEmailKeys() {
public function testActionEmailKeys(): void {
/** @var EmailActivation $expiredConfirmation */
$expiredConfirmation = $this->tester->grabFixture('emailActivations', 'deeplyExpiredConfirmation');
@@ -33,7 +33,7 @@ class CleanupControllerTest extends TestCase {
$this->tester->cantSeeRecord(EmailActivation::class, ['key' => $expiredConfirmation->key]);
}
public function testActionWebSessions() {
public function testActionWebSessions(): void {
/** @var AccountSession $expiredSession */
$expiredSession = $this->tester->grabFixture('accountsSessions', 'very-expired-session');
/** @var AccountSession $notRefreshedSession */
@@ -48,9 +48,8 @@ class CleanupControllerTest extends TestCase {
$this->assertSame($totalSessionsCount - 2, (int)AccountSession::find()->count());
}
public function testActionOauthClients() {
/** @var OauthClient $deletedClient */
$totalClientsCount = OauthClient::find()->includeDeleted()->count();
public function testActionOauthClients(): void {
$totalClientsCount = (int)OauthClient::find()->includeDeleted()->count();
$controller = new CleanupController('cleanup', Yii::$app);
$this->assertSame(0, $controller->actionOauthClients());

View File

@@ -1,12 +1,14 @@
<?php
/* @var $className string the new migration class name */
/**
* @var string $className the new migration class name
*/
echo "<?php\n";
?>
use console\db\Migration;
class <?= $className ?> extends Migration {
class <?= $className; ?> extends Migration {
public function safeUp() {