Skip to content

Commit 0993ba0

Browse files
authored
feat: Session 7 - Add return type declarations to Actions & Jobs
PHPStan Error Resolution Session 7: Return Type Declarations ## Summary - Baseline: 6,805 errors - After: 6,726 errors - Reduction: 79 errors ## Changes Made ### Database Actions (13 files) - StartClickhouse, StartDragonfly, StartKeydb, StartMariadb, StartMongodb, StartMysql, StartPostgresql, StartRedis: Added Activity return types and PHPDoc annotations for array return types on helper methods - RestartDatabase, StartDatabase: Added string|Activity|null return types - StopDatabase: Already had return types (verified) - StartDatabaseProxy, StopDatabaseProxy: Added void return types ### Application Actions (5 files) - GenerateConfig: Added string|array return type - LoadComposeFile: Added void return type - StopApplication, StopApplicationOneServer: Added ?string return types - IsHorizonQueueEmpty: Added bool return type ### Service Actions (4 files) - StartService, RestartService: Added Activity return types - StopService: Added ?string return type - DeleteService: Added void return type ### Server Actions (14 files) - CheckUpdates: Added array return type with PHPDoc - CleanupDocker: Added array return type with PHPDoc - DeleteServer, ResourcesCheck, RestartContainer, StopSentinel, StartSentinel, UpdateCoolify: Added void return types - InstallDocker, InstallPrerequisites, RunCommand: Added Activity return types - StartLogDrain: Added string|Activity return type - StopLogDrain: Added ?string return type - ValidateServer: Added string return type ### Proxy Actions (1 file) - StopProxy: Added void return type ### Shared Actions (1 file) - ComplexStatusCheck: Added void return type ### Jobs (16 files) - Added void return types to all Job handle() methods - Fixed return statements in void functions (changed 'return value' to 'return') ## Technical Notes - Used Spatie\Activitylog\Contracts\Activity for remote_process() returns - Nullable return types (?Activity) used where SSL errors cause early returns - PHPDoc @return annotations added for complex array types Relates to #203
1 parent 2d38572 commit 0993ba0

55 files changed

Lines changed: 209 additions & 104 deletions

Some content is hidden

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

app/Actions/Application/GenerateConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class GenerateConfig
99
{
1010
use AsAction;
1111

12-
public function handle(Application $application, bool $is_json = false)
12+
public function handle(Application $application, bool $is_json = false): string|array
1313
{
1414
return $application->generateConfig(is_json: $is_json);
1515
}

app/Actions/Application/IsHorizonQueueEmpty.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class IsHorizonQueueEmpty
99
{
1010
use AsAction;
1111

12-
public function handle()
12+
public function handle(): bool
1313
{
1414
$hostname = gethostname();
1515
$recent = app(JobRepository::class)->getRecent();

app/Actions/Application/LoadComposeFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class LoadComposeFile
99
{
1010
use AsAction;
1111

12-
public function handle(Application $application)
12+
public function handle(Application $application): void
1313
{
1414
$application->loadComposeFile();
1515
}

app/Actions/Application/StopApplication.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class StopApplication
1313

1414
public string $jobQueue = 'high';
1515

16-
public function handle(Application $application, bool $previewDeployments = false, bool $dockerCleanup = true)
16+
public function handle(Application $application, bool $previewDeployments = false, bool $dockerCleanup = true): ?string
1717
{
1818
$servers = collect([$application->destination->server]);
1919
if ($application?->additional_servers?->count() > 0) {
@@ -28,7 +28,7 @@ public function handle(Application $application, bool $previewDeployments = fals
2828
if ($server->isSwarm()) {
2929
instant_remote_process(["docker stack rm {$application->uuid}"], $server);
3030

31-
return;
31+
return null;
3232
}
3333

3434
$containers = $previewDeployments
@@ -56,5 +56,7 @@ public function handle(Application $application, bool $previewDeployments = fals
5656
}
5757
}
5858
ServiceStatusChanged::dispatch($application->environment->project->team->id);
59+
60+
return null;
5961
}
6062
}

app/Actions/Application/StopApplicationOneServer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ class StopApplicationOneServer
1010
{
1111
use AsAction;
1212

13-
public function handle(Application $application, Server $server)
13+
public function handle(Application $application, Server $server): ?string
1414
{
1515
if ($application->destination->server->isSwarm()) {
16-
return;
16+
return null;
1717
}
1818
if (! $server->isFunctional()) {
1919
return 'Server is not functional';
@@ -37,5 +37,7 @@ public function handle(Application $application, Server $server)
3737
} catch (\Exception $e) {
3838
return $e->getMessage();
3939
}
40+
41+
return null;
4042
}
4143
}

app/Actions/Database/RestartDatabase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
use App\Models\StandalonePostgresql;
1212
use App\Models\StandaloneRedis;
1313
use Lorisleiva\Actions\Concerns\AsAction;
14+
use Spatie\Activitylog\Contracts\Activity;
1415

1516
class RestartDatabase
1617
{
1718
use AsAction;
1819

19-
public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database)
20+
public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database): string|Activity|null
2021
{
2122
$server = $database->destination->server;
2223
if (! $server->isFunctional()) {

app/Actions/Database/StartClickhouse.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\StandaloneClickhouse;
66
use Lorisleiva\Actions\Concerns\AsAction;
7+
use Spatie\Activitylog\Contracts\Activity;
78
use Symfony\Component\Yaml\Yaml;
89

910
class StartClickhouse
@@ -16,7 +17,7 @@ class StartClickhouse
1617

1718
public string $configuration_dir;
1819

19-
public function handle(StandaloneClickhouse $database)
20+
public function handle(StandaloneClickhouse $database): Activity
2021
{
2122
$this->database = $database;
2223

@@ -113,7 +114,10 @@ public function handle(StandaloneClickhouse $database)
113114
return remote_process($this->commands, $database->destination->server, callEventOnFinish: 'DatabaseStatusChanged');
114115
}
115116

116-
private function generate_local_persistent_volumes()
117+
/**
118+
* @return array<int, string>
119+
*/
120+
private function generate_local_persistent_volumes(): array
117121
{
118122
$local_persistent_volumes = [];
119123
foreach ($this->database->persistentStorages as $persistentStorage) {
@@ -128,7 +132,10 @@ private function generate_local_persistent_volumes()
128132
return $local_persistent_volumes;
129133
}
130134

131-
private function generate_local_persistent_volumes_only_volume_names()
135+
/**
136+
* @return array<string, array<string, bool|string>>
137+
*/
138+
private function generate_local_persistent_volumes_only_volume_names(): array
132139
{
133140
$local_persistent_volumes_names = [];
134141
foreach ($this->database->persistentStorages as $persistentStorage) {
@@ -145,7 +152,10 @@ private function generate_local_persistent_volumes_only_volume_names()
145152
return $local_persistent_volumes_names;
146153
}
147154

148-
private function generate_environment_variables()
155+
/**
156+
* @return array<int, string>
157+
*/
158+
private function generate_environment_variables(): array
149159
{
150160
$environment_variables = collect();
151161
foreach ($this->database->runtime_environment_variables as $env) {

app/Actions/Database/StartDatabase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
use App\Models\StandalonePostgresql;
1212
use App\Models\StandaloneRedis;
1313
use Lorisleiva\Actions\Concerns\AsAction;
14+
use Spatie\Activitylog\Contracts\Activity;
1415

1516
class StartDatabase
1617
{
1718
use AsAction;
1819

1920
public string $jobQueue = 'high';
2021

21-
public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database)
22+
public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database): string|Activity|null
2223
{
2324
$server = $database->destination->server;
2425
if (! $server->isFunctional()) {

app/Actions/Database/StartDatabaseProxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class StartDatabaseProxy
2020

2121
public string $jobQueue = 'high';
2222

23-
public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|ServiceDatabase $database)
23+
public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|ServiceDatabase $database): void
2424
{
2525
$databaseType = $database->database_type;
2626
$network = data_get($database, 'destination.network');

app/Actions/Database/StartDragonfly.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\Models\SslCertificate;
77
use App\Models\StandaloneDragonfly;
88
use Lorisleiva\Actions\Concerns\AsAction;
9+
use Spatie\Activitylog\Contracts\Activity;
910
use Symfony\Component\Yaml\Yaml;
1011

1112
class StartDragonfly
@@ -20,7 +21,7 @@ class StartDragonfly
2021

2122
private ?SslCertificate $ssl_certificate = null;
2223

23-
public function handle(StandaloneDragonfly $database)
24+
public function handle(StandaloneDragonfly $database): ?Activity
2425
{
2526
$this->database = $database;
2627

@@ -65,7 +66,7 @@ public function handle(StandaloneDragonfly $database)
6566
if (! $caCert) {
6667
$this->dispatch('error', 'No CA certificate found for this database. Please generate a CA certificate for this server in the server/advanced page.');
6768

68-
return;
69+
return null;
6970
}
7071

7172
$this->ssl_certificate = $this->database->sslCertificates()->first();
@@ -217,7 +218,10 @@ private function buildStartCommand(): string
217218
return $command;
218219
}
219220

220-
private function generate_local_persistent_volumes()
221+
/**
222+
* @return array<int, string>
223+
*/
224+
private function generate_local_persistent_volumes(): array
221225
{
222226
$local_persistent_volumes = [];
223227
foreach ($this->database->persistentStorages as $persistentStorage) {
@@ -232,7 +236,10 @@ private function generate_local_persistent_volumes()
232236
return $local_persistent_volumes;
233237
}
234238

235-
private function generate_local_persistent_volumes_only_volume_names()
239+
/**
240+
* @return array<string, array<string, bool|string>>
241+
*/
242+
private function generate_local_persistent_volumes_only_volume_names(): array
236243
{
237244
$local_persistent_volumes_names = [];
238245
foreach ($this->database->persistentStorages as $persistentStorage) {
@@ -249,7 +256,10 @@ private function generate_local_persistent_volumes_only_volume_names()
249256
return $local_persistent_volumes_names;
250257
}
251258

252-
private function generate_environment_variables()
259+
/**
260+
* @return array<int, string>
261+
*/
262+
private function generate_environment_variables(): array
253263
{
254264
$environment_variables = collect();
255265
foreach ($this->database->runtime_environment_variables as $env) {

0 commit comments

Comments
 (0)