Skip to content

Commit 766fba5

Browse files
AndrewKostkadeer-wmde
authored andcommitted
Add code linting using Laravel Pint (#940)
* Add code linting using Laravel Pint * Update linting ruleset * Automatically fix linting errors
1 parent df3fa17 commit 766fba5

301 files changed

Lines changed: 3595 additions & 4292 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/composer.test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ jobs:
5050
run: docker compose exec -e APP_ENV=testing -T api vendor/bin/phpunit
5151
- name: Psalm
5252
run: docker compose exec -T api vendor/bin/psalm
53+
- name: Linting
54+
run: docker compose exec api vendor/bin/pint --test -v
5355

5456
- name: Run elasticsearch index deletion integration test
5557
run: docker compose exec -e RUN_PHPUNIT_INTEGRATION_TEST=1 -e ELASTICSEARCH_HOST=elasticsearch.svc:9200 -T api vendor/bin/phpunit tests/Jobs/Integration/ElasticSearchIndexDeleteTest.php

.php_cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ Currently most of the tests require the DB connection to exist.
102102
docker compose exec api vendor/bin/phpunit
103103
```
104104

105+
### Linting
106+
107+
```sh
108+
docker compose exec api vendor/bin/pint --test -v
109+
```
110+
105111
#### Debugging
106112

107113
If you get a CORS error from an API when testing, it might be due to an exception internally, resulting in a 500 response with no CORS.

app/ComplaintRecord.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
* @property \Illuminate\Support\Carbon|null $dispatched_at
1818
* @property \Illuminate\Support\Carbon|null $created_at
1919
* @property \Illuminate\Support\Carbon|null $updated_at
20+
*
2021
* @mixin \Eloquent
2122
*/
22-
class ComplaintRecord extends Model
23-
{
23+
class ComplaintRecord extends Model {
2424
use HasFactory;
2525

2626
protected $fillable = [
@@ -30,8 +30,7 @@ class ComplaintRecord extends Model
3030
'offending_urls',
3131
];
3232

33-
public function markAsDispatched()
34-
{
33+
public function markAsDispatched() {
3534
$this->dispatched_at = Carbon::now();
3635
}
3736
}

app/Console/Commands/Invitation/All.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use App\Invitation;
66
use Illuminate\Console\Command;
77

8-
class All extends Command
9-
{
8+
class All extends Command {
109
protected $signature = 'wbs-invitation:all';
1110

1211
protected $description = 'List all current invitations';
@@ -16,8 +15,7 @@ class All extends Command
1615
*
1716
* @return mixed
1817
*/
19-
public function handle()
20-
{
18+
public function handle() {
2119
foreach (Invitation::all() as $invitation) {
2220
$this->line($invitation->code);
2321
}

app/Console/Commands/Invitation/Create.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use App\Jobs\InvitationCreateJob;
66
use Illuminate\Console\Command;
77

8-
class Create extends Command
9-
{
8+
class Create extends Command {
109
protected $signature = 'wbs-invitation:create {code}';
1110

1211
protected $description = 'Create an invitation';
@@ -16,15 +15,14 @@ class Create extends Command
1615
*
1716
* @return mixed
1817
*/
19-
public function handle()
20-
{
18+
public function handle() {
2119
$code = trim($this->argument('code'));
2220
$jobResult = (new InvitationCreateJob($code))->handle();
2321

2422
if ($jobResult) {
25-
$this->line('Successfully created invitation: '.$code);
23+
$this->line('Successfully created invitation: ' . $code);
2624
} else {
27-
$this->line('Failed to create invitation: '.$code);
25+
$this->line('Failed to create invitation: ' . $code);
2826
}
2927

3028
return 0;

app/Console/Commands/Invitation/CreateBulk.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
namespace App\Console\Commands\Invitation;
44

5+
use App\Helper\InviteHelper;
56
use App\Jobs\InvitationCreateJob;
67
use Illuminate\Console\Command;
7-
use App\Helper\InviteHelper;
88

9-
class CreateBulk extends Command
10-
{
9+
class CreateBulk extends Command {
1110
protected $signature = 'wbs-invitation:create-bulk {numCodes}';
1211

1312
protected $description = 'Create an bulk invitations';
@@ -17,20 +16,19 @@ class CreateBulk extends Command
1716
*
1817
* @return mixed
1918
*/
20-
public function handle()
21-
{
19+
public function handle() {
2220
$numCodes = trim($this->argument('numCodes'));
23-
$helper = new InviteHelper();
21+
$helper = new InviteHelper;
2422

25-
for($i = 0; $i < $numCodes; $i++) {
23+
for ($i = 0; $i < $numCodes; $i++) {
2624
$code = $helper->generate();
2725
$jobResult = (new InvitationCreateJob($code))->handle();
2826

2927
if ($jobResult) {
30-
$this->line('Successfully created invitation: '.$code);
31-
} else {
32-
$this->line('Failed to create invitation: '.$code);
33-
}
28+
$this->line('Successfully created invitation: ' . $code);
29+
} else {
30+
$this->line('Failed to create invitation: ' . $code);
31+
}
3432
}
3533

3634
return 0;

app/Console/Commands/Invitation/Delete.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use App\Jobs\InvitationDeleteJob;
66
use Illuminate\Console\Command;
77

8-
class Delete extends Command
9-
{
8+
class Delete extends Command {
109
protected $signature = 'wbs-invitation:delete {code}';
1110

1211
protected $description = 'Delete an invitation';
@@ -16,8 +15,7 @@ class Delete extends Command
1615
*
1716
* @return mixed
1817
*/
19-
public function handle()
20-
{
18+
public function handle() {
2119
$code = trim($this->argument('code'));
2220
(new InvitationDeleteJob($code))->handle();
2321

app/Console/Commands/RebuildQueryserviceData.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,33 @@
33
namespace App\Console\Commands;
44

55
use App\Constants\MediawikiNamespace;
6+
use App\Jobs\SpawnQueryserviceUpdaterJob;
7+
use App\QueryserviceNamespace;
68
use App\Traits;
9+
use App\Wiki;
10+
use App\WikiSetting;
711
use Illuminate\Console\Command;
8-
use Illuminate\Support\Facades\Http;
912
use Illuminate\Support\Facades\Log;
1013
use Illuminate\Support\Facades\Queue;
11-
use App\Wiki;
12-
use App\WikiSetting;
13-
use App\QueryserviceNamespace;
14-
use App\Jobs\SpawnQueryserviceUpdaterJob;
1514

16-
class RebuildQueryserviceData extends Command
17-
{
15+
class RebuildQueryserviceData extends Command {
1816
use Traits\PageFetcher;
1917

2018
protected $signature = 'wbs-qs:rebuild {--domain=*} {--chunkSize=50} {--queueName=manual-intervention} {--sparqlUrlFormat=http://queryservice.default.svc.cluster.local:9999/bigdata/namespace/%s/sparql}';
2119

2220
protected $description = 'Rebuild the queryservice data for a certain wiki or all wikis';
2321

2422
protected int $chunkSize;
23+
2524
protected string $sparqlUrlFormat;
25+
2626
protected string $queueName;
2727

28-
public function handle()
29-
{
28+
public function handle() {
3029
$this->chunkSize = intval($this->option('chunkSize'));
3130
$this->sparqlUrlFormat = $this->option('sparqlUrlFormat');
3231
$this->queueName = $this->option('queueName');
33-
$this->apiUrl = getenv('PLATFORM_MW_BACKEND_HOST').'/w/api.php';
32+
$this->apiUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php';
3433

3534
$wikiDomains = $this->option('domain');
3635
$exitCode = 0;
@@ -48,7 +47,7 @@ public function handle()
4847
$sparqlUrl = $this->getSparqlUrl($wiki);
4948
} catch (\Exception $ex) {
5049
Log::error(
51-
'Failed to get prerequisites for enqueuing wiki '.$wiki->domain.', will not dispatch jobs.',
50+
'Failed to get prerequisites for enqueuing wiki ' . $wiki->domain . ', will not dispatch jobs.',
5251
[$ex],
5352
);
5453
$exitCode = 1;
@@ -66,24 +65,24 @@ public function handle()
6665
}
6766
$jobTotal += count($entityChunks);
6867
$processedWikis += 1;
69-
Log::info('Dispatched '.count($entityChunks).' job(s) for wiki '.$wiki->domain.'.');
68+
Log::info('Dispatched ' . count($entityChunks) . ' job(s) for wiki ' . $wiki->domain . '.');
7069
}
7170

7271
Log::info(
73-
'Done. Jobs dispatched: '.$jobTotal.' Wikis processed: '.$processedWikis.' Wikis skipped: '.$skippedWikis
72+
'Done. Jobs dispatched: ' . $jobTotal . ' Wikis processed: ' . $processedWikis . ' Wikis skipped: ' . $skippedWikis
7473
);
74+
7575
return $exitCode;
7676
}
7777

78-
private function getEntitiesForWiki (Wiki $wiki): array
79-
{
78+
private function getEntitiesForWiki(Wiki $wiki): array {
8079
$items = $this->fetchPagesInNamespace($wiki->domain, MediawikiNamespace::item);
8180
$properties = $this->fetchPagesInNamespace($wiki->domain, MediawikiNamespace::property);
8281

8382
$lexemesSetting = WikiSetting::where(
8483
[
8584
'wiki_id' => $wiki->id,
86-
'name' => WikiSetting::wwExtEnableWikibaseLexeme
85+
'name' => WikiSetting::wwExtEnableWikibaseLexeme,
8786
],
8887
)->first();
8988
$hasLexemesEnabled = $lexemesSetting !== null && $lexemesSetting->value === '1';
@@ -93,22 +92,22 @@ private function getEntitiesForWiki (Wiki $wiki): array
9392

9493
$merged = array_merge($items, $properties, $lexemes);
9594
$this->stripPrefixes($merged);
95+
9696
return $merged;
9797
}
9898

99-
private function getSparqlUrl (Wiki $wiki): string
100-
{
99+
private function getSparqlUrl(Wiki $wiki): string {
101100
$match = QueryserviceNamespace::where(['wiki_id' => $wiki->id])->first();
102101
if (!$match) {
103102
throw new \Exception(
104-
'Unable to find queryservice namespace record for wiki '.$wiki->domain
103+
'Unable to find queryservice namespace record for wiki ' . $wiki->domain
105104
);
106105
}
106+
107107
return sprintf($this->sparqlUrlFormat, $match->namespace);
108108
}
109109

110-
private static function stripPrefixes (array &$items): void
111-
{
110+
private static function stripPrefixes(array &$items): void {
112111
foreach ($items as &$item) {
113112
$e = explode(':', $item);
114113
$item = end($e);

app/Console/Commands/ScheduleStatsUpdates.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
namespace App\Console\Commands;
44

5-
use Illuminate\Console\Command;
5+
use App\Jobs\PlatformStatsSummaryJob;
66
use App\Jobs\SiteStatsUpdateJob;
77
use App\Wiki;
8-
use App\Jobs\PlatformStatsSummaryJob;
8+
use Illuminate\Console\Command;
99
use Illuminate\Support\Facades\Bus;
1010
use Illuminate\Support\Facades\Log;
11+
1112
/**
1213
* Schedules jobs for updating site_stats per wiki then platformsummaryjob
1314
*/
14-
class ScheduleStatsUpdates extends Command
15-
{
15+
class ScheduleStatsUpdates extends Command {
1616
/**
1717
* The name and signature of the console command.
1818
*
@@ -32,8 +32,7 @@ class ScheduleStatsUpdates extends Command
3232
*
3333
* @return void
3434
*/
35-
public function __construct()
36-
{
35+
public function __construct() {
3736
parent::__construct();
3837
}
3938

@@ -42,20 +41,20 @@ public function __construct()
4241
*
4342
* @return int
4443
*/
45-
public function handle()
46-
{
44+
public function handle() {
4745
$siteStatsUpdateJobs = [];
4846
foreach (Wiki::all() as $wiki) {
4947
$siteStatsUpdateJobs[] = new SiteStatsUpdateJob($wiki->id);
5048
}
5149

52-
Log::info(__METHOD__ . ": Scheduling updates for " . count($siteStatsUpdateJobs) . " wikis.");
50+
Log::info(__METHOD__ . ': Scheduling updates for ' . count($siteStatsUpdateJobs) . ' wikis.');
5351

5452
Bus::batch($siteStatsUpdateJobs)
5553
->allowFailures()
5654
->finally(function () {
57-
dispatch(new PlatformStatsSummaryJob());
55+
dispatch(new PlatformStatsSummaryJob);
5856
})->dispatch();
57+
5958
return 0;
6059
}
6160
}

0 commit comments

Comments
 (0)