From 1dbe6f3861f459f1eba53457ce36544185f3e9d2 Mon Sep 17 00:00:00 2001 From: Andrew Kostka Date: Wed, 3 Sep 2025 08:36:53 +0000 Subject: [PATCH] Fix linting for total number of entites metric --- app/Metrics/App/WikiMetrics.php | 8 +++--- ..._item_count_to_wiki_daily_merics_table.php | 9 +++---- ...rties_count_to_wiki_daily_merics_table.php | 9 +++---- ...xemes_count_to_wiki_daily_merics_table.php | 9 +++---- ...hemas_count_to_wiki_daily_merics_table.php | 9 +++---- tests/Metrics/WikiMetricsTest.php | 26 +++++++++---------- 6 files changed, 28 insertions(+), 42 deletions(-) diff --git a/app/Metrics/App/WikiMetrics.php b/app/Metrics/App/WikiMetrics.php index 4eaf6f8fb..7df603e93 100644 --- a/app/Metrics/App/WikiMetrics.php +++ b/app/Metrics/App/WikiMetrics.php @@ -183,8 +183,7 @@ private function getNumberOfUsersPerActivityType(): array { ]; } - private function getNumberOfEntities() : array - { + private function getNumberOfEntities(): array { $wikiDb = $this->wiki->wikiDb; $tablePage = $wikiDb->name . '.' . $wikiDb->prefix . '_page'; $query = "SELECT @@ -200,9 +199,10 @@ private function getNumberOfEntities() : array $conn = $manager->connection('mw'); $pdo = $conn->getPdo(); $result = $pdo->query($query)->fetchAll(PDO::FETCH_ASSOC); - if (count($result) === 0){ - return [ 120 => 0, 122 => 0, 146 => 0, 640 => 0 ]; + if (count($result) === 0) { + return [120 => 0, 122 => 0, 146 => 0, 640 => 0]; } + return array_column($result, 'count', 'namespace'); } } diff --git a/database/migrations/2025_07_30_104606_add_item_count_to_wiki_daily_merics_table.php b/database/migrations/2025_07_30_104606_add_item_count_to_wiki_daily_merics_table.php index 2beb8c96b..41c33d8a2 100644 --- a/database/migrations/2025_07_30_104606_add_item_count_to_wiki_daily_merics_table.php +++ b/database/migrations/2025_07_30_104606_add_item_count_to_wiki_daily_merics_table.php @@ -4,13 +4,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. */ - public function up(): void - { + public function up(): void { Schema::table('wiki_daily_metrics', function (Blueprint $table) { $table->integer('item_count')->nullable()->default(null); }); @@ -19,8 +17,7 @@ public function up(): void /** * Reverse the migrations. */ - public function down(): void - { + public function down(): void { Schema::table('wiki_daily_metrics', function (Blueprint $table) { $table->dropColumn('item_count'); }); diff --git a/database/migrations/2025_07_30_104622_add_properties_count_to_wiki_daily_merics_table.php b/database/migrations/2025_07_30_104622_add_properties_count_to_wiki_daily_merics_table.php index 3d2fa9848..48223e1d9 100644 --- a/database/migrations/2025_07_30_104622_add_properties_count_to_wiki_daily_merics_table.php +++ b/database/migrations/2025_07_30_104622_add_properties_count_to_wiki_daily_merics_table.php @@ -4,13 +4,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. */ - public function up(): void - { + public function up(): void { Schema::table('wiki_daily_metrics', function (Blueprint $table) { $table->integer('property_count')->nullable()->default(null); }); @@ -19,8 +17,7 @@ public function up(): void /** * Reverse the migrations. */ - public function down(): void - { + public function down(): void { Schema::table('wiki_daily_metrics', function (Blueprint $table) { $table->dropColumn('property_count'); }); diff --git a/database/migrations/2025_07_30_104657_add_lexemes_count_to_wiki_daily_merics_table.php b/database/migrations/2025_07_30_104657_add_lexemes_count_to_wiki_daily_merics_table.php index f617454e7..638e6f43c 100644 --- a/database/migrations/2025_07_30_104657_add_lexemes_count_to_wiki_daily_merics_table.php +++ b/database/migrations/2025_07_30_104657_add_lexemes_count_to_wiki_daily_merics_table.php @@ -4,13 +4,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. */ - public function up(): void - { + public function up(): void { Schema::table('wiki_daily_metrics', function (Blueprint $table) { $table->integer('lexeme_count')->nullable()->default(null); }); @@ -19,8 +17,7 @@ public function up(): void /** * Reverse the migrations. */ - public function down(): void - { + public function down(): void { Schema::table('wiki_daily_metrics', function (Blueprint $table) { $table->dropColumn('lexeme_count'); }); diff --git a/database/migrations/2025_07_30_104719_add_entity_schemas_count_to_wiki_daily_merics_table.php b/database/migrations/2025_07_30_104719_add_entity_schemas_count_to_wiki_daily_merics_table.php index 7a06e2bb2..a00e975f7 100644 --- a/database/migrations/2025_07_30_104719_add_entity_schemas_count_to_wiki_daily_merics_table.php +++ b/database/migrations/2025_07_30_104719_add_entity_schemas_count_to_wiki_daily_merics_table.php @@ -4,13 +4,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. */ - public function up(): void - { + public function up(): void { Schema::table('wiki_daily_metrics', function (Blueprint $table) { $table->integer('entity_schema_count')->nullable()->default(null); }); @@ -19,8 +17,7 @@ public function up(): void /** * Reverse the migrations. */ - public function down(): void - { + public function down(): void { Schema::table('wiki_daily_metrics', function (Blueprint $table) { $table->dropColumn('entity_schema_count'); }); diff --git a/tests/Metrics/WikiMetricsTest.php b/tests/Metrics/WikiMetricsTest.php index 59743e572..9a6b0f11f 100644 --- a/tests/Metrics/WikiMetricsTest.php +++ b/tests/Metrics/WikiMetricsTest.php @@ -168,10 +168,9 @@ public function testSaveNullForFailedRequestOfTriplesCount() { ]); } - public function testSavesEntityCountsCorrectly() - { + public function testSavesEntityCountsCorrectly() { $wiki = Wiki::factory()->create([ - 'domain' => 'entitycounttest.wikibase.cloud' + 'domain' => 'entitycounttest.wikibase.cloud', ]); $wikiDb = WikiDb::first(); @@ -200,7 +199,7 @@ public function testSavesEntityCountsCorrectly() 'page_random' => 0, 'page_touched' => random_bytes(10), 'page_latest' => 1, - 'page_len' => 2 + 'page_len' => 2, ], // item [ 'page_namespace' => 120, @@ -209,7 +208,7 @@ public function testSavesEntityCountsCorrectly() 'page_random' => 0, 'page_touched' => random_bytes(10), 'page_latest' => 0, - 'page_len' => 2 + 'page_len' => 2, ], // item [ 'page_namespace' => 122, @@ -218,8 +217,7 @@ public function testSavesEntityCountsCorrectly() 'page_random' => 0, 'page_touched' => random_bytes(10), 'page_latest' => 1, - 'page_len' => 2] - , // property + 'page_len' => 2], // property [ 'page_namespace' => 640, 'page_is_redirect' => 0, @@ -227,7 +225,7 @@ public function testSavesEntityCountsCorrectly() 'page_random' => 0, 'page_touched' => random_bytes(10), 'page_latest' => 1, - 'page_len' => 2 + 'page_len' => 2, ], // entity schema [ 'page_namespace' => 146, @@ -236,7 +234,7 @@ public function testSavesEntityCountsCorrectly() 'page_random' => 0, 'page_touched' => random_bytes(10), 'page_latest' => 1, - 'page_len' => 2 + 'page_len' => 2, ], // lexeme [ 'page_namespace' => 640, @@ -245,7 +243,7 @@ public function testSavesEntityCountsCorrectly() 'page_random' => 0, 'page_touched' => random_bytes(10), 'page_latest' => 1, - 'page_len' => 2 + 'page_len' => 2, ], // entity schema ]); WikiDailyMetrics::create([ @@ -253,12 +251,12 @@ public function testSavesEntityCountsCorrectly() 'wiki_id' => $wiki->id, 'date' => now()->subDay()->toDateString(), 'pages' => 6, - 'is_deleted' => 0 + 'is_deleted' => 0, ]); - (new WikiMetrics())->saveMetrics($wiki); + (new WikiMetrics)->saveMetrics($wiki); - //clean up after the test + // clean up after the test $wiki->forceDelete(); Schema::dropIfExists($tablePage); @@ -267,7 +265,7 @@ public function testSavesEntityCountsCorrectly() 'item_count' => 2, 'property_count' => 1, 'lexeme_count' => 1, - 'entity_schema_count' => 1 // the redirect should be ignored + 'entity_schema_count' => 1, // the redirect should be ignored ]); } }