Skip to content

Commit d1c2d0e

Browse files
committed
Fix PHPStan level 5 errors (batch 2)
- Console commands: Cast option values to int for subHours/plural calls - Filesystem: Add ignores for FtpAdapter/SftpAdapter interface quirk - Foundation: Fix str_replace type, array_filter callback, add type assertion - Horizon: Change Exception to Throwable for job failures (matches Laravel) - Horizon: Cast Redis timestamps to string, add higher-order proxy ignore - Prompts: Add ignores for intentional array_values on lists - Validation: Add ignores for defensive array_values/array_filter - Cors: Add ignore for bug (to be fixed in separate PR)
1 parent a18464c commit d1c2d0e

27 files changed

+38
-36
lines changed

src/filesystem/src/FilesystemManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public function createFtpDriver(array $config): FileSystem
213213
/* @phpstan-ignore-next-line */
214214
$adapter = new FtpAdapter(FtpConnectionOptions::fromArray($config));
215215

216-
return new FilesystemAdapter($this->createFlysystem($adapter, $config), $adapter, $config);
216+
return new FilesystemAdapter($this->createFlysystem($adapter, $config), $adapter, $config); // @phpstan-ignore-line (FtpAdapter/SftpAdapter implement interface)
217217
}
218218

219219
/**
@@ -233,7 +233,7 @@ public function createSftpDriver(array $config): FileSystem
233233
/* @phpstan-ignore-next-line */
234234
$adapter = new SftpAdapter($provider, $root, $visibility);
235235

236-
return new FilesystemAdapter($this->createFlysystem($adapter, $config), $adapter, $config);
236+
return new FilesystemAdapter($this->createFlysystem($adapter, $config), $adapter, $config); // @phpstan-ignore-line (FtpAdapter/SftpAdapter implement interface)
237237
}
238238

239239
/**

src/foundation/src/Concerns/ResolvesDumpSource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ protected function resolveSourceHref(string $file, ?int $line)
165165

166166
return str_replace(
167167
['{file}', '{line}'],
168-
[$file, is_null($line) ? 1 : $line],
168+
[$file, (string) ($line ?? 1)],
169169
$href,
170170
);
171171
}

src/foundation/src/Console/Commands/VendorPublishCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected function getPackagePublishes(): array
120120
),
121121
$extra
122122
);
123-
$packages = array_filter($packages, fn ($provider) => count($provider));
123+
$packages = array_filter($packages, fn ($provider) => count($provider) > 0);
124124

125125
$publishes = [];
126126
foreach ($packages as $packageName => $extra) {

src/foundation/src/Console/Kernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public function registerCommand(string $command): void
222222
return;
223223
}
224224

225-
$this->getArtisan()->add($command);
225+
$this->getArtisan()->add($command); // @phpstan-ignore argument.type (interface narrower than parent)
226226
}
227227

228228
/**

src/foundation/src/Exceptions/Handler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,8 @@ public function dontReportDuplicates()
847847

848848
/**
849849
* Determine if the given exception is an HTTP exception.
850+
*
851+
* @phpstan-assert-if-true HyperfHttpException $e
850852
*/
851853
protected function isHttpException(Throwable $e): bool
852854
{

src/foundation/src/Http/Kernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function onRequest($swooleRequest, $swooleResponse): void
7171
}
7272

7373
$this->dispatchRequestReceivedEvent(
74-
$request = $this->coreMiddleware->dispatch($request),
74+
$request = $this->coreMiddleware->dispatch($request), // @phpstan-ignore argument.type (dispatch returns Request impl)
7575
$response
7676
);
7777

@@ -110,7 +110,7 @@ public function onRequest($swooleRequest, $swooleResponse): void
110110
protected function convertUploadedFiles(array $files): array
111111
{
112112
return array_map(function ($file) {
113-
if (is_null($file) || (is_array($file) && empty(array_filter($file)))) {
113+
if (is_null($file) || (is_array($file) && empty(array_filter($file)))) { // @phpstan-ignore arrayFilter.same (nested arrays may contain nulls)
114114
return $file;
115115
}
116116

src/foundation/src/Http/Traits/HasCasts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected function castInput(string $key, mixed $value, bool $validate = true):
131131
case 'double':
132132
return $this->fromFloat($value);
133133
case 'decimal':
134-
return $this->asDecimal($value, explode(':', $this->getCasts()[$key], 2)[1]);
134+
return $this->asDecimal($value, (int) explode(':', $this->getCasts()[$key], 2)[1]);
135135
case 'string':
136136
return (string) $value;
137137
case 'bool':

src/horizon/src/AutoScaler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function poolsByQueue(Supervisor $supervisor): Collection
5757
protected function timeToClearPerQueue(Supervisor $supervisor, Collection $pools): Collection
5858
{
5959
return $pools->mapWithKeys(function ($pool, $queue) use ($supervisor) {
60-
$queues = collect(explode(',', $queue))->map(function ($_queue) use ($supervisor) {
60+
$queues = collect(explode(',', $queue))->map(function ($_queue) use ($supervisor) { // @phpstan-ignore argument.unresolvableType
6161
// @phpstan-ignore-next-line RedisQueue has readyNow method
6262
$size = $this->queue->connection($supervisor->options->connection)->readyNow($_queue);
6363

@@ -68,8 +68,8 @@ protected function timeToClearPerQueue(Supervisor $supervisor, Collection $pools
6868
});
6969

7070
return [$queue => [
71-
'size' => $queues->sum('size'),
72-
'time' => $queues->sum('time'),
71+
'size' => $queues->sum('size'), // @phpstan-ignore argument.unresolvableType
72+
'time' => $queues->sum('time'), // @phpstan-ignore argument.unresolvableType
7373
]];
7474
});
7575
}

src/horizon/src/Contracts/JobRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Hypervel\Horizon\Contracts;
66

7-
use Exception;
87
use Hypervel\Horizon\JobPayload;
98
use Hypervel\Support\Collection;
109
use stdClass;
10+
use Throwable;
1111

1212
interface JobRepository
1313
{
@@ -144,7 +144,7 @@ public function findFailed(string $id): ?stdClass;
144144
/**
145145
* Mark the job as failed.
146146
*/
147-
public function failed(Exception $exception, string $connection, string $queue, JobPayload $payload): void;
147+
public function failed(Throwable $exception, string $connection, string $queue, JobPayload $payload): void;
148148

149149
/**
150150
* Store the retry job ID on the original job record.

src/horizon/src/Events/JobFailed.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44

55
namespace Hypervel\Horizon\Events;
66

7-
use Exception;
87
use Hypervel\Queue\Jobs\Job;
8+
use Throwable;
99

1010
class JobFailed extends RedisEvent
1111
{
1212
/**
1313
* Create a new event instance.
1414
*
15-
* @param Exception $exception the exception that caused the failure
15+
* @param Throwable $exception the exception that caused the failure
1616
* @param Job $job the queue job instance
1717
*/
1818
public function __construct(
19-
public Exception $exception,
19+
public Throwable $exception,
2020
public Job $job,
2121
string $payload
2222
) {

0 commit comments

Comments
 (0)