Skip to content

Commit fa07ada

Browse files
AndrewKostkadeer-wmde
authored andcommitted
Fix linting for total number of entites metric (#969)
1 parent 584b87f commit fa07ada

6 files changed

Lines changed: 28 additions & 42 deletions

app/Metrics/App/WikiMetrics.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ private function getNumberOfUsersPerActivityType(): array {
183183
];
184184
}
185185

186-
private function getNumberOfEntities() : array
187-
{
186+
private function getNumberOfEntities(): array {
188187
$wikiDb = $this->wiki->wikiDb;
189188
$tablePage = $wikiDb->name . '.' . $wikiDb->prefix . '_page';
190189
$query = "SELECT
@@ -200,9 +199,10 @@ private function getNumberOfEntities() : array
200199
$conn = $manager->connection('mw');
201200
$pdo = $conn->getPdo();
202201
$result = $pdo->query($query)->fetchAll(PDO::FETCH_ASSOC);
203-
if (count($result) === 0){
204-
return [ 120 => 0, 122 => 0, 146 => 0, 640 => 0 ];
202+
if (count($result) === 0) {
203+
return [120 => 0, 122 => 0, 146 => 0, 640 => 0];
205204
}
205+
206206
return array_column($result, 'count', 'namespace');
207207
}
208208
}

database/migrations/2025_07_30_104606_add_item_count_to_wiki_daily_merics_table.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
return new class extends Migration
8-
{
7+
return new class extends Migration {
98
/**
109
* Run the migrations.
1110
*/
12-
public function up(): void
13-
{
11+
public function up(): void {
1412
Schema::table('wiki_daily_metrics', function (Blueprint $table) {
1513
$table->integer('item_count')->nullable()->default(null);
1614
});
@@ -19,8 +17,7 @@ public function up(): void
1917
/**
2018
* Reverse the migrations.
2119
*/
22-
public function down(): void
23-
{
20+
public function down(): void {
2421
Schema::table('wiki_daily_metrics', function (Blueprint $table) {
2522
$table->dropColumn('item_count');
2623
});

database/migrations/2025_07_30_104622_add_properties_count_to_wiki_daily_merics_table.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
return new class extends Migration
8-
{
7+
return new class extends Migration {
98
/**
109
* Run the migrations.
1110
*/
12-
public function up(): void
13-
{
11+
public function up(): void {
1412
Schema::table('wiki_daily_metrics', function (Blueprint $table) {
1513
$table->integer('property_count')->nullable()->default(null);
1614
});
@@ -19,8 +17,7 @@ public function up(): void
1917
/**
2018
* Reverse the migrations.
2119
*/
22-
public function down(): void
23-
{
20+
public function down(): void {
2421
Schema::table('wiki_daily_metrics', function (Blueprint $table) {
2522
$table->dropColumn('property_count');
2623
});

database/migrations/2025_07_30_104657_add_lexemes_count_to_wiki_daily_merics_table.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
return new class extends Migration
8-
{
7+
return new class extends Migration {
98
/**
109
* Run the migrations.
1110
*/
12-
public function up(): void
13-
{
11+
public function up(): void {
1412
Schema::table('wiki_daily_metrics', function (Blueprint $table) {
1513
$table->integer('lexeme_count')->nullable()->default(null);
1614
});
@@ -19,8 +17,7 @@ public function up(): void
1917
/**
2018
* Reverse the migrations.
2119
*/
22-
public function down(): void
23-
{
20+
public function down(): void {
2421
Schema::table('wiki_daily_metrics', function (Blueprint $table) {
2522
$table->dropColumn('lexeme_count');
2623
});

database/migrations/2025_07_30_104719_add_entity_schemas_count_to_wiki_daily_merics_table.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
return new class extends Migration
8-
{
7+
return new class extends Migration {
98
/**
109
* Run the migrations.
1110
*/
12-
public function up(): void
13-
{
11+
public function up(): void {
1412
Schema::table('wiki_daily_metrics', function (Blueprint $table) {
1513
$table->integer('entity_schema_count')->nullable()->default(null);
1614
});
@@ -19,8 +17,7 @@ public function up(): void
1917
/**
2018
* Reverse the migrations.
2119
*/
22-
public function down(): void
23-
{
20+
public function down(): void {
2421
Schema::table('wiki_daily_metrics', function (Blueprint $table) {
2522
$table->dropColumn('entity_schema_count');
2623
});

tests/Metrics/WikiMetricsTest.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,9 @@ public function testSaveNullForFailedRequestOfTriplesCount() {
168168
]);
169169
}
170170

171-
public function testSavesEntityCountsCorrectly()
172-
{
171+
public function testSavesEntityCountsCorrectly() {
173172
$wiki = Wiki::factory()->create([
174-
'domain' => 'entitycounttest.wikibase.cloud'
173+
'domain' => 'entitycounttest.wikibase.cloud',
175174
]);
176175

177176
$wikiDb = WikiDb::first();
@@ -200,7 +199,7 @@ public function testSavesEntityCountsCorrectly()
200199
'page_random' => 0,
201200
'page_touched' => random_bytes(10),
202201
'page_latest' => 1,
203-
'page_len' => 2
202+
'page_len' => 2,
204203
], // item
205204
[
206205
'page_namespace' => 120,
@@ -209,7 +208,7 @@ public function testSavesEntityCountsCorrectly()
209208
'page_random' => 0,
210209
'page_touched' => random_bytes(10),
211210
'page_latest' => 0,
212-
'page_len' => 2
211+
'page_len' => 2,
213212
], // item
214213
[
215214
'page_namespace' => 122,
@@ -218,16 +217,15 @@ public function testSavesEntityCountsCorrectly()
218217
'page_random' => 0,
219218
'page_touched' => random_bytes(10),
220219
'page_latest' => 1,
221-
'page_len' => 2]
222-
, // property
220+
'page_len' => 2], // property
223221
[
224222
'page_namespace' => 640,
225223
'page_is_redirect' => 0,
226224
'page_title' => 'bar',
227225
'page_random' => 0,
228226
'page_touched' => random_bytes(10),
229227
'page_latest' => 1,
230-
'page_len' => 2
228+
'page_len' => 2,
231229
], // entity schema
232230
[
233231
'page_namespace' => 146,
@@ -236,7 +234,7 @@ public function testSavesEntityCountsCorrectly()
236234
'page_random' => 0,
237235
'page_touched' => random_bytes(10),
238236
'page_latest' => 1,
239-
'page_len' => 2
237+
'page_len' => 2,
240238
], // lexeme
241239
[
242240
'page_namespace' => 640,
@@ -245,20 +243,20 @@ public function testSavesEntityCountsCorrectly()
245243
'page_random' => 0,
246244
'page_touched' => random_bytes(10),
247245
'page_latest' => 1,
248-
'page_len' => 2
246+
'page_len' => 2,
249247
], // entity schema
250248
]);
251249
WikiDailyMetrics::create([
252250
'id' => $wiki->id . '_' . now()->subDay()->toDateString(),
253251
'wiki_id' => $wiki->id,
254252
'date' => now()->subDay()->toDateString(),
255253
'pages' => 6,
256-
'is_deleted' => 0
254+
'is_deleted' => 0,
257255
]);
258256

259-
(new WikiMetrics())->saveMetrics($wiki);
257+
(new WikiMetrics)->saveMetrics($wiki);
260258

261-
//clean up after the test
259+
// clean up after the test
262260
$wiki->forceDelete();
263261
Schema::dropIfExists($tablePage);
264262

@@ -267,7 +265,7 @@ public function testSavesEntityCountsCorrectly()
267265
'item_count' => 2,
268266
'property_count' => 1,
269267
'lexeme_count' => 1,
270-
'entity_schema_count' => 1 // the redirect should be ignored
268+
'entity_schema_count' => 1, // the redirect should be ignored
271269
]);
272270
}
273271
}

0 commit comments

Comments
 (0)