Skip to content

Commit b84f689

Browse files
author
Tray2
committed
Make PHPStan happy at level 6
1 parent 5af5db1 commit b84f689

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
.phpunit.result.cache
33
vendor
4+
build

phpstan.neon.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ includes:
22
- ./phpstan-baseline.neon
33

44
parameters:
5-
level: 5
5+
level: 6
66
paths:
77
- src
88
tmpDir: build/phpstan
99
checkOctaneCompatibility: true
1010
checkModelProperties: true
1111
checkMissingIterableValueType: false
12+
treatPhpDocTypesAsCertain: false

src/Commands/MakeSeederCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Console\Command;
77
use Illuminate\Contracts\Console\PromptsForMissingInput;
88
use Illuminate\Contracts\Filesystem\FileNotFoundException;
9+
use Symfony\Component\Console\Input\InputArgument;
910
use Symfony\Component\Console\Input\InputInterface;
1011
use Symfony\Component\Console\Output\OutputInterface;
1112
use Tray2\MakeSeeder\CsvParser;
@@ -82,7 +83,7 @@ protected function loadModels(): array
8283
return (new ModelFinder())->find();
8384
}
8485

85-
protected function showSelect(InputInterface $input, $argument, mixed $label): void
86+
protected function showSelect(InputInterface $input, InputArgument $argument, mixed $label): void
8687
{
8788
$options = $this->loadModels();
8889
$input->setArgument($argument->getName(), select(
@@ -91,15 +92,15 @@ protected function showSelect(InputInterface $input, $argument, mixed $label): v
9192
));
9293
}
9394

94-
protected function showTextInput(InputInterface $input, $argument, mixed $label): void
95+
protected function showTextInput(InputInterface $input, InputArgument $argument, mixed $label): void
9596
{
9697
$input->setArgument($argument->getName(), text(
9798
label: $label,
9899
validate: fn($value) => empty($value) ? "The {$argument->getName()} is required." : null,
99100
));
100101
}
101102

102-
protected function getLabel($argument): mixed
103+
protected function getLabel(InputArgument $argument): mixed
103104
{
104105
return $this->promptForMissingArgumentsUsing()[$argument->getName()] ??
105106
'What is ' . lcfirst($argument->getDescription() ?: ('the ' . $argument->getName())) . '?';
@@ -114,7 +115,8 @@ protected function promptForMissingArguments(InputInterface $input, OutputInterf
114115
$label = $this->getLabel($argument);
115116

116117
if ($label instanceof Closure) {
117-
return $input->setArgument($argument->getName(), $label());
118+
$input->setArgument($argument->getName(), $label());
119+
return;
118120
}
119121

120122
if (is_array($label)) {

src/CsvParser.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,26 @@ public function generateFile(string $csvPath, bool $noHeader = false): void
3030
{
3131
$stub = file_get_contents($this->stubsDir);
3232

33+
if(! $stub) {
34+
return;
35+
}
36+
3337
$migration = fopen($this->destinationDir . $this->model . 'Seeder.php', 'wb');
3438

3539
$stub = str_replace(['{Model}', '{Seeder}', '{Rows}'],
3640
[$this->model, $this->generateSeeders($csvPath, $noHeader), $this->row], $stub);
37-
fwrite($migration, $stub );
38-
fclose($migration);
41+
if ($migration) {
42+
fwrite($migration, $stub );
43+
fclose($migration);
44+
}
3945
}
4046

41-
protected function generateSeeders(string $csvPath, $noHeader): string
47+
protected function generateSeeders(string $csvPath, bool $noHeader): string
4248
{
4349
$fLoader = new FileLoader($csvPath, $this->separator);
50+
4451
$rows = array_chunk($fLoader->getContent(), $fLoader->columnsCount());
52+
$columns = [];
4553

4654
$seeder = '';
4755
if ($noHeader) {

src/Exceptions/ClassNotFoundException.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Tray2\MakeSeeder\Exceptions;
44

55
use Exception;
6+
use Throwable;
67

78
class ClassNotFoundException extends Exception
89
{

0 commit comments

Comments
 (0)