Skip to content

Commit 493cbb0

Browse files
authored
Add phpstan level 7(#544)
1 parent c22bb1f commit 493cbb0

File tree

437 files changed

+4504
-2192
lines changed

Some content is hidden

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

437 files changed

+4504
-2192
lines changed

.github/workflows/code-quality.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: code-quality
2+
3+
on:
4+
push:
5+
branches:
6+
- 2.x
7+
pull_request:
8+
branches:
9+
- 2.x
10+
11+
jobs:
12+
tests:
13+
runs-on: ubuntu-22.04
14+
15+
strategy:
16+
fail-fast: true
17+
matrix:
18+
php: [ 8.2 ]
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Setup PHP
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: ${{ matrix.php }}
27+
28+
- name: Cache Composer packages
29+
id: composer-cache
30+
uses: actions/cache@v4
31+
with:
32+
path: vendor
33+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
34+
restore-keys: |
35+
${{ runner.os }}-php-
36+
37+
- name: Install dependencies
38+
if: steps.composer-cache.outputs.cache-hit != 'true'
39+
run: composer install --prefer-dist --no-progress --no-suggest
40+
41+
- name: Run PHPStan
42+
run: ./vendor/bin/phpstan analyse

app/Actions/CronJob/CreateCronJob.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
class CreateCronJob
1212
{
13+
/**
14+
* @param array<string, mixed> $input
15+
*/
1316
public function create(Server $server, array $input): CronJob
1417
{
1518
$cronJob = new CronJob([
@@ -28,6 +31,10 @@ public function create(Server $server, array $input): CronJob
2831
return $cronJob;
2932
}
3033

34+
/**
35+
* @param array<string, mixed> $input
36+
* @return array<string, array<mixed>>
37+
*/
3138
public static function rules(array $input, Server $server): array
3239
{
3340
$rules = [

app/Actions/Database/CreateDatabase.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
use App\Enums\DatabaseStatus;
66
use App\Models\Database;
77
use App\Models\Server;
8+
use App\Models\Service;
89
use Illuminate\Validation\Rule;
910
use Illuminate\Validation\ValidationException;
1011

1112
class CreateDatabase
1213
{
14+
/**
15+
* @param array<string, mixed> $input
16+
*/
1317
public function create(Server $server, array $input): Database
1418
{
1519
$database = new Database([
@@ -18,8 +22,12 @@ public function create(Server $server, array $input): Database
1822
'collation' => $input['collation'],
1923
'name' => $input['name'],
2024
]);
25+
26+
/** @var Service $service */
27+
$service = $server->database();
28+
2129
/** @var \App\SSH\Services\Database\Database $databaseHandler */
22-
$databaseHandler = $server->database()->handler();
30+
$databaseHandler = $service->handler();
2331
$databaseHandler->create($database->name, $database->charset, $database->collation);
2432
$database->status = DatabaseStatus::READY;
2533
$database->save();
@@ -34,6 +42,9 @@ public function create(Server $server, array $input): Database
3442
}
3543

3644
/**
45+
* @param array<string, mixed> $input
46+
* @return array<string, mixed>
47+
*
3748
* @throws ValidationException
3849
*/
3950
public static function rules(Server $server, array $input): array

app/Actions/Database/CreateDatabaseUser.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
use App\Enums\DatabaseUserStatus;
66
use App\Models\DatabaseUser;
77
use App\Models\Server;
8+
use App\Models\Service;
89
use App\SSH\Services\Database\Database;
910
use Illuminate\Validation\Rule;
1011
use Illuminate\Validation\ValidationException;
1112

1213
class CreateDatabaseUser
1314
{
1415
/**
16+
* @param array<string, mixed> $input
17+
* @param array<string> $links
18+
*
1519
* @throws ValidationException
1620
*/
1721
public function create(Server $server, array $input, array $links = []): DatabaseUser
@@ -23,8 +27,12 @@ public function create(Server $server, array $input, array $links = []): Databas
2327
'host' => (isset($input['remote']) && $input['remote']) || isset($input['host']) ? $input['host'] : 'localhost',
2428
'databases' => $links,
2529
]);
30+
31+
/** @var Service $service */
32+
$service = $server->database();
33+
2634
/** @var Database $databaseHandler */
27-
$databaseHandler = $server->database()->handler();
35+
$databaseHandler = $service->handler();
2836
$databaseHandler->createUser(
2937
$databaseUser->username,
3038
$databaseUser->password,
@@ -41,6 +49,9 @@ public function create(Server $server, array $input, array $links = []): Databas
4149
}
4250

4351
/**
52+
* @param array<string, mixed> $input
53+
* @return array<string, mixed>
54+
*
4455
* @throws ValidationException
4556
*/
4657
public static function rules(Server $server, array $input): array

app/Actions/Database/DeleteDatabase.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44

55
use App\Models\Database;
66
use App\Models\Server;
7+
use App\Models\Service;
78

89
class DeleteDatabase
910
{
1011
public function delete(Server $server, Database $database): void
1112
{
12-
$server->database()->handler()->delete($database->name);
13+
/** @var Service $service */
14+
$service = $server->database();
15+
/** @var \App\SSH\Services\Database\Database $handler */
16+
$handler = $service->handler();
17+
$handler->delete($database->name);
1318
$database->delete();
1419
}
1520
}

app/Actions/Database/DeleteDatabaseUser.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44

55
use App\Models\DatabaseUser;
66
use App\Models\Server;
7+
use App\Models\Service;
8+
use App\SSH\Services\Database\Database;
79

810
class DeleteDatabaseUser
911
{
1012
public function delete(Server $server, DatabaseUser $databaseUser): void
1113
{
12-
$server->database()->handler()->deleteUser($databaseUser->username, $databaseUser->host);
14+
/** @var Service $service */
15+
$service = $server->database();
16+
/** @var Database $handler */
17+
$handler = $service->handler();
18+
$handler->deleteUser($databaseUser->username, $databaseUser->host);
1319
$databaseUser->delete();
1420
}
1521
}

app/Actions/Database/LinkUser.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
use App\Models\Database;
66
use App\Models\DatabaseUser;
77
use App\Models\Server;
8+
use App\Models\Service;
89
use Illuminate\Validation\Rule;
910
use Illuminate\Validation\ValidationException;
1011

1112
class LinkUser
1213
{
1314
/**
15+
* @param array<string, mixed> $input
16+
* @return DatabaseUser $databaseUser
17+
*
1418
* @throws ValidationException
1519
*/
1620
public function link(DatabaseUser $databaseUser, array $input): DatabaseUser
@@ -29,14 +33,20 @@ public function link(DatabaseUser $databaseUser, array $input): DatabaseUser
2933

3034
$databaseUser->databases = $input['databases'];
3135

36+
/** @var Service $service */
37+
$service = $databaseUser->server->database();
38+
39+
/** @var \App\SSH\Services\Database\Database $handler */
40+
$handler = $service->handler();
41+
3242
// Unlink the user from all databases
33-
$databaseUser->server->database()->handler()->unlink(
43+
$handler->unlink(
3444
$databaseUser->username,
3545
$databaseUser->host
3646
);
3747

3848
// Link the user to the selected databases
39-
$databaseUser->server->database()->handler()->link(
49+
$handler->link(
4050
$databaseUser->username,
4151
$databaseUser->host,
4252
$databaseUser->databases
@@ -49,6 +59,10 @@ public function link(DatabaseUser $databaseUser, array $input): DatabaseUser
4959
return $databaseUser;
5060
}
5161

62+
/**
63+
* @param array<string, mixed> $input
64+
* @return array<string, mixed>
65+
*/
5266
public static function rules(Server $server, array $input): array
5367
{
5468
return [

app/Actions/Database/ManageBackup.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
class ManageBackup
1515
{
1616
/**
17+
* @param array<string, mixed> $input
18+
*
1719
* @throws AuthorizationException
1820
* @throws ValidationException
1921
*/
@@ -35,6 +37,9 @@ public function create(Server $server, array $input): Backup
3537
return $backup;
3638
}
3739

40+
/**
41+
* @param array<string, mixed> $input
42+
*/
3843
public function update(Backup $backup, array $input): void
3944
{
4045
$backup->interval = $input['interval'] == 'custom' ? $input['custom_interval'] : $input['interval'];
@@ -47,7 +52,7 @@ public function delete(Backup $backup): void
4752
$backup->status = BackupStatus::DELETING;
4853
$backup->save();
4954

50-
dispatch(function () use ($backup) {
55+
dispatch(function () use ($backup): void {
5156
$files = $backup->files;
5257
foreach ($files as $file) {
5358
$file->status = BackupFileStatus::DELETING;
@@ -60,6 +65,10 @@ public function delete(Backup $backup): void
6065
});
6166
}
6267

68+
/**
69+
* @param array<string, mixed> $input
70+
* @return array<string, mixed>
71+
*/
6372
public static function rules(Server $server, array $input): array
6473
{
6574
$rules = [

app/Actions/Database/ManageBackupFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function delete(BackupFile $file): void
2828
$file->status = BackupFileStatus::DELETING;
2929
$file->save();
3030

31-
dispatch(function () use ($file) {
31+
dispatch(function () use ($file): void {
3232
$file->deleteFile();
3333
});
3434
}

app/Actions/Database/RestoreBackup.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
use App\Enums\BackupFileStatus;
66
use App\Models\BackupFile;
77
use App\Models\Database;
8+
use App\Models\Service;
89

910
class RestoreBackup
1011
{
12+
/**
13+
* @param array<string, mixed> $input
14+
*/
1115
public function restore(BackupFile $backupFile, array $input): void
1216
{
1317
/** @var Database $database */
@@ -16,19 +20,24 @@ public function restore(BackupFile $backupFile, array $input): void
1620
$backupFile->restored_to = $database->name;
1721
$backupFile->save();
1822

19-
dispatch(function () use ($backupFile, $database) {
23+
dispatch(function () use ($backupFile, $database): void {
24+
/** @var Service $service */
25+
$service = $database->server->database();
2026
/** @var \App\SSH\Services\Database\Database $databaseHandler */
21-
$databaseHandler = $database->server->database()->handler();
27+
$databaseHandler = $service->handler();
2228
$databaseHandler->restoreBackup($backupFile, $database->name);
2329
$backupFile->status = BackupFileStatus::RESTORED;
2430
$backupFile->restored_at = now();
2531
$backupFile->save();
26-
})->catch(function () use ($backupFile) {
32+
})->catch(function () use ($backupFile): void {
2733
$backupFile->status = BackupFileStatus::RESTORE_FAILED;
2834
$backupFile->save();
2935
})->onConnection('ssh');
3036
}
3137

38+
/**
39+
* @return array<string, array<string>>
40+
*/
3241
public static function rules(): array
3342
{
3443
return [

0 commit comments

Comments
 (0)