Skip to content

Commit

Permalink
Make PHPStan happy at level 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Tray2 committed Oct 31, 2023
1 parent 5af5db1 commit b84f689
Showing 5 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.phpunit.result.cache
vendor
build
3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -2,10 +2,11 @@ includes:
- ./phpstan-baseline.neon

parameters:
level: 5
level: 6
paths:
- src
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false
treatPhpDocTypesAsCertain: false
10 changes: 6 additions & 4 deletions src/Commands/MakeSeederCommand.php
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
use Illuminate\Console\Command;
use Illuminate\Contracts\Console\PromptsForMissingInput;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Tray2\MakeSeeder\CsvParser;
@@ -82,7 +83,7 @@ protected function loadModels(): array
return (new ModelFinder())->find();
}

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

protected function showTextInput(InputInterface $input, $argument, mixed $label): void
protected function showTextInput(InputInterface $input, InputArgument $argument, mixed $label): void
{
$input->setArgument($argument->getName(), text(
label: $label,
validate: fn($value) => empty($value) ? "The {$argument->getName()} is required." : null,
));
}

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

if ($label instanceof Closure) {
return $input->setArgument($argument->getName(), $label());
$input->setArgument($argument->getName(), $label());
return;
}

if (is_array($label)) {
14 changes: 11 additions & 3 deletions src/CsvParser.php
Original file line number Diff line number Diff line change
@@ -30,18 +30,26 @@ public function generateFile(string $csvPath, bool $noHeader = false): void
{
$stub = file_get_contents($this->stubsDir);

if(! $stub) {
return;
}

$migration = fopen($this->destinationDir . $this->model . 'Seeder.php', 'wb');

$stub = str_replace(['{Model}', '{Seeder}', '{Rows}'],
[$this->model, $this->generateSeeders($csvPath, $noHeader), $this->row], $stub);
fwrite($migration, $stub );
fclose($migration);
if ($migration) {
fwrite($migration, $stub );
fclose($migration);
}
}

protected function generateSeeders(string $csvPath, $noHeader): string
protected function generateSeeders(string $csvPath, bool $noHeader): string
{
$fLoader = new FileLoader($csvPath, $this->separator);

$rows = array_chunk($fLoader->getContent(), $fLoader->columnsCount());
$columns = [];

$seeder = '';
if ($noHeader) {
1 change: 1 addition & 0 deletions src/Exceptions/ClassNotFoundException.php
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
namespace Tray2\MakeSeeder\Exceptions;

use Exception;
use Throwable;

class ClassNotFoundException extends Exception
{

0 comments on commit b84f689

Please sign in to comment.