Skip to content

Commit 56cd00e

Browse files
committed
feat: update PHPStan to level 5
1 parent 17bf4c2 commit 56cd00e

File tree

9 files changed

+78
-58
lines changed

9 files changed

+78
-58
lines changed

phpstan.neon.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 1
2+
level: 5
33
paths:
44
- src
55
reportUnmatchedIgnoredErrors: false

src/Application.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
class Application extends BaseApplication
2626
{
2727
/**
28-
* Get the builds path. With, optionally, a path to append to the base path.
28+
* Get the `builds` path. With, optionally, a path to append to the base path.
2929
*/
3030
public function buildsPath(string $path = ''): string
3131
{
@@ -86,15 +86,13 @@ public function configurationIsCached(): bool
8686
}
8787

8888
/**
89-
* Register all of the configured providers.
89+
* Register all the configured providers.
9090
*/
9191
public function registerConfiguredProviders(): void
9292
{
9393
$providers = Collection::make($this['config']['app.providers'])
9494
->partition(
95-
function ($provider) {
96-
return Str::startsWith($provider, 'Illuminate\\');
97-
}
95+
fn ($provider) => Str::startsWith($provider, 'Illuminate\\')
9896
);
9997

10098
$providers->splice(

src/Commands/BuildCommand.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Console\Command\SignalableCommandInterface;
1919
use Symfony\Component\Console\Helper\ProgressBar;
2020
use Symfony\Component\Console\Input\InputInterface;
21+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
2122
use Symfony\Component\Console\Output\NullOutput;
2223
use Symfony\Component\Console\Output\OutputInterface;
2324
use Symfony\Component\Process\Process;
@@ -42,21 +43,21 @@ final class BuildCommand extends Command implements SignalableCommandInterface
4243
*
4344
* @var string|null
4445
*/
45-
private static $config;
46+
private static string|null $config = null;
4647

4748
/**
4849
* Holds the box.json on is original state.
4950
*
5051
* @var string|null
5152
*/
52-
private static $box;
53+
private static string|null $box = null;
5354

5455
/**
5556
* Holds the command original output.
5657
*
57-
* @var \Symfony\Component\Console\Output\OutputInterface
58+
* @var OutputInterface
5859
*/
59-
private $originalOutput;
60+
private OutputInterface $originalOutput;
6061

6162
/**
6263
* {@inheritdoc}
@@ -94,7 +95,7 @@ public function handleSignal(int $signal): void
9495
/**
9596
* Builds the application into a single file.
9697
*/
97-
private function build(string $name): BuildCommand
98+
private function build(string $name): void
9899
{
99100
/*
100101
* We prepare the application for a build, moving it to production. Then,
@@ -108,8 +109,6 @@ private function build(string $name): BuildCommand
108109
$this->output->writeln(
109110
sprintf(' Compiled successfully: <fg=green>%s</>', $this->app->buildsPath($name))
110111
);
111-
112-
return $this;
113112
}
114113

115114
private function compile(string $name): BuildCommand
@@ -128,6 +127,7 @@ private function compile(string $name): BuildCommand
128127
$this->getTimeout()
129128
);
130129

130+
/** @phpstan-ignore-next-line This is an instance of `ConsoleOutputInterface` */
131131
$section = tap($this->originalOutput->section())->write('');
132132

133133
$progressBar = tap(

src/Commands/Command.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use function func_get_args;
1717
use Illuminate\Console\Command as BaseCommand;
1818
use Illuminate\Console\Scheduling\Schedule;
19+
use LaravelZero\Framework\Application;
1920
use LaravelZero\Framework\Providers\CommandRecorder\CommandRecorderRepository;
2021
use function str_repeat;
2122
use function strlen;
@@ -25,21 +26,19 @@ abstract class Command extends BaseCommand
2526
/**
2627
* Holds an instance of the app, if any.
2728
*
28-
* @var \LaravelZero\Framework\Application
29+
* @var Application
2930
*/
3031
protected $app;
3132

3233
/**
3334
* Define the command's schedule.
34-
*
35-
* @return void
3635
*/
37-
public function schedule(Schedule $schedule)
36+
public function schedule(Schedule $schedule): void
3837
{
3938
}
4039

4140
/**
42-
* {@inheritdoc}
41+
* @param Application $laravel
4342
*/
4443
public function setLaravel($laravel): void
4544
{
@@ -75,7 +74,7 @@ public function title(string $title): Command
7574
/**
7675
* {@inheritdoc}
7776
*/
78-
public function call($command, array $arguments = [])
77+
public function call($command, array $arguments = []): int
7978
{
8079
resolve(CommandRecorderRepository::class)->create($command, $arguments);
8180

@@ -85,7 +84,7 @@ public function call($command, array $arguments = [])
8584
/**
8685
* {@inheritdoc}
8786
*/
88-
public function callSilent($command, array $arguments = [])
87+
public function callSilent($command, array $arguments = []): int
8988
{
9089
resolve(CommandRecorderRepository::class)->create($command, $arguments, CommandRecorderRepository::MODE_SILENT);
9190

src/Components/Database/Provider.php

+42-20
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,30 @@
1515

1616
use function class_exists;
1717
use function collect;
18+
use Illuminate\Contracts\Config\Repository;
19+
use Illuminate\Database\ConnectionResolverInterface;
20+
use Illuminate\Database\Console\Factories\FactoryMakeCommand;
21+
use Illuminate\Database\Console\Migrations\FreshCommand;
22+
use Illuminate\Database\Console\Migrations\InstallCommand;
23+
use Illuminate\Database\Console\Migrations\MigrateCommand;
24+
use Illuminate\Database\Console\Migrations\MigrateMakeCommand;
25+
use Illuminate\Database\Console\Migrations\RefreshCommand;
26+
use Illuminate\Database\Console\Migrations\ResetCommand;
27+
use Illuminate\Database\Console\Migrations\RollbackCommand;
28+
use Illuminate\Database\Console\Migrations\StatusCommand;
29+
use Illuminate\Database\Console\Seeds\SeedCommand;
30+
use Illuminate\Database\Console\Seeds\SeederMakeCommand;
31+
use Illuminate\Database\Console\WipeCommand;
32+
use Illuminate\Database\DatabaseServiceProvider;
1833
use Illuminate\Database\Migrations\MigrationCreator;
34+
use Illuminate\Database\Migrations\MigrationRepositoryInterface;
35+
use Illuminate\Database\MigrationServiceProvider;
36+
use Illuminate\Foundation\Console\ModelMakeCommand;
37+
use Illuminate\Foundation\Providers\ComposerServiceProvider;
1938
use Illuminate\Support\Facades\File;
2039
use function is_array;
2140
use LaravelZero\Framework\Components\AbstractComponentProvider;
41+
use SplFileInfo;
2242

2343
/**
2444
* @internal
@@ -30,7 +50,7 @@ class Provider extends AbstractComponentProvider
3050
*/
3151
public function isAvailable(): bool
3252
{
33-
return class_exists(\Illuminate\Database\DatabaseServiceProvider::class)
53+
return class_exists(DatabaseServiceProvider::class)
3454
&& is_array($this->app['config']->get('database', false))
3555
&& $this->app['config']->get('database.useDefaultProvider', true) === true;
3656
}
@@ -57,25 +77,25 @@ public function boot(): void
5777
if ($this->app->environment() !== 'production') {
5878
$this->commands(
5979
[
60-
\Illuminate\Database\Console\Migrations\MigrateMakeCommand::class,
61-
\Illuminate\Database\Console\Factories\FactoryMakeCommand::class,
62-
\Illuminate\Database\Console\Seeds\SeederMakeCommand::class,
63-
\Illuminate\Foundation\Console\ModelMakeCommand::class,
64-
\Illuminate\Database\Console\Seeds\SeedCommand::class,
80+
MigrateMakeCommand::class,
81+
FactoryMakeCommand::class,
82+
SeederMakeCommand::class,
83+
ModelMakeCommand::class,
84+
SeedCommand::class,
6585
]
6686
);
6787
}
6888

6989
$this->commands(
7090
[
71-
\Illuminate\Database\Console\Migrations\FreshCommand::class,
72-
\Illuminate\Database\Console\Migrations\InstallCommand::class,
73-
\Illuminate\Database\Console\Migrations\MigrateCommand::class,
74-
\Illuminate\Database\Console\Migrations\RefreshCommand::class,
75-
\Illuminate\Database\Console\Migrations\ResetCommand::class,
76-
\Illuminate\Database\Console\Migrations\RollbackCommand::class,
77-
\Illuminate\Database\Console\Migrations\StatusCommand::class,
78-
\Illuminate\Database\Console\WipeCommand::class,
91+
FreshCommand::class,
92+
InstallCommand::class,
93+
MigrateCommand::class,
94+
RefreshCommand::class,
95+
ResetCommand::class,
96+
RollbackCommand::class,
97+
StatusCommand::class,
98+
WipeCommand::class,
7999
]
80100
);
81101
}
@@ -87,12 +107,12 @@ public function boot(): void
87107
*/
88108
protected function registerDatabaseService(): void
89109
{
90-
$this->app->alias('db', \Illuminate\Database\ConnectionResolverInterface::class);
91-
$this->app->register(\Illuminate\Database\DatabaseServiceProvider::class);
110+
$this->app->alias('db', ConnectionResolverInterface::class);
111+
$this->app->register(DatabaseServiceProvider::class);
92112

93113
if (File::exists($this->app->databasePath('seeders'))) {
94114
collect(File::files($this->app->databasePath('seeders')))->each(
95-
fn ($file) => File::requireOnce($file)
115+
fn (SplFileInfo $file) => File::requireOnce((string) $file)
96116
);
97117
}
98118
}
@@ -102,15 +122,17 @@ protected function registerDatabaseService(): void
102122
*/
103123
protected function registerMigrationService(): void
104124
{
125+
/** @var Repository $config */
105126
$config = $this->app['config'];
106127
$config->set('database.migrations', $config->get('database.migrations') ?: 'migrations');
107-
$this->app->register(\Illuminate\Foundation\Providers\ComposerServiceProvider::class);
108-
$this->app->register(\Illuminate\Database\MigrationServiceProvider::class);
128+
129+
$this->app->register(ComposerServiceProvider::class);
130+
$this->app->register(MigrationServiceProvider::class);
109131
$this->app->alias('migration.creator', MigrationCreator::class);
110132

111133
$this->app->alias(
112134
'migration.repository',
113-
\Illuminate\Database\Migrations\MigrationRepositoryInterface::class
135+
MigrationRepositoryInterface::class
114136
);
115137

116138
$this->app->singleton(

src/Components/Logo/FigletString.php

+8-10
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
*/
2222
final class FigletString
2323
{
24-
private $string;
24+
private string $string;
2525

2626
/** @var Figlet */
27-
private $figlet;
27+
private Figlet $figlet;
2828

2929
public const DEFAULT_FONT = __DIR__.DIRECTORY_SEPARATOR.'fonts'.DIRECTORY_SEPARATOR.'big.flf';
3030

@@ -36,7 +36,7 @@ public function __construct(string $string, array $options)
3636
$this->parseOptions($options);
3737
}
3838

39-
private function parseOptions(array $config)
39+
private function parseOptions(array $config): void
4040
{
4141
$this
4242
->font($config['font'] ?? self::DEFAULT_FONT)
@@ -45,7 +45,7 @@ private function parseOptions(array $config)
4545
->rightToLeft($config['rightToLeft'] ?? null);
4646
}
4747

48-
private function font(?string $font)
48+
private function font(?string $font): self
4949
{
5050
if (is_null($font)) {
5151
return $this;
@@ -56,14 +56,14 @@ private function font(?string $font)
5656
return $this;
5757
}
5858

59-
private function outputWidth(int $outputWidth)
59+
private function outputWidth(int $outputWidth): self
6060
{
6161
$this->figlet->setOutputWidth($outputWidth);
6262

6363
return $this;
6464
}
6565

66-
private function justification(?string $justification)
66+
private function justification(?string $justification): self
6767
{
6868
switch ($justification) {
6969
case 'left':
@@ -85,7 +85,7 @@ private function justification(?string $justification)
8585
return $this;
8686
}
8787

88-
private function rightToLeft(?string $rightToLeft)
88+
private function rightToLeft(?string $rightToLeft): void
8989
{
9090
switch ($rightToLeft) {
9191
case 'right-to-left':
@@ -100,14 +100,12 @@ private function rightToLeft(?string $rightToLeft)
100100
default:
101101
throw new \InvalidArgumentException('Invalid value given for the `logo.rightToLeft` option');
102102
}
103-
104-
return $this;
105103
}
106104

107105
public function __toString()
108106
{
109107
$rendered = $this->figlet->render($this->string);
110108

111-
return "\n$rendered\n";
109+
return "\n{$rendered}\n";
112110
}
113111
}

src/Kernel.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Kernel extends BaseKernel
3333
*
3434
* @var string[]
3535
*/
36-
protected $developmentCommands = [
36+
protected array $developmentCommands = [
3737
Commands\BuildCommand::class,
3838
Commands\RenameCommand::class,
3939
Commands\MakeCommand::class,
@@ -47,7 +47,7 @@ class Kernel extends BaseKernel
4747
*
4848
* @var string[]
4949
*/
50-
protected $developmentOnlyCommands = [
50+
protected array $developmentOnlyCommands = [
5151
TestCommand::class,
5252
];
5353

@@ -151,11 +151,13 @@ protected function commands(): void
151151

152152
/*
153153
* Loads commands paths.
154+
*
155+
* @phpstan-ignore-next-line
154156
*/
155157
$this->load($config->get('commands.paths', $this->app->path('Commands')));
156158

157159
/**
158-
* Loads configurated commands.
160+
* Loads configured commands.
159161
*/
160162
$commands = collect($config->get('commands.add', []))->merge($config->get('commands.hidden', []));
161163

src/Providers/Composer/Composer.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ final class Composer implements ComposerContract
3939
*
4040
* @return void
4141
*/
42-
public function __construct(Application $app)
42+
public function __construct(private readonly Application $app)
4343
{
44-
$this->app = $app;
4544
}
4645

4746
/**
@@ -69,7 +68,7 @@ public function remove(string $package, bool $dev = false): bool
6968
*/
7069
public function createProject(string $skeleton, string $projectName, array $options): bool
7170
{
72-
$cmd = collect("composer create-project $skeleton $projectName")
71+
$cmd = collect(["composer create-project {$skeleton} {$projectName}"])
7372
->merge($options)
7473
->implode(' ');
7574

0 commit comments

Comments
 (0)