Skip to content

Commit

Permalink
Fix disambiguations
Browse files Browse the repository at this point in the history
  • Loading branch information
bastien-phi committed Aug 22, 2023
1 parent 755e1d5 commit f68c5ee
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
16 changes: 8 additions & 8 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ parameters:
path: src/Commands/BuilderCommand.php

-
message: "#^Parameter \\$options of function Laravel\\\\Prompts\\\\select expects array\\<int\\|string, string\\>\\|Illuminate\\\\Support\\\\Collection\\<int\\|string, string\\>, Illuminate\\\\Support\\\\Collection\\<int, class\\-string\\<Illuminate\\\\Database\\\\Eloquent\\\\Model\\>\\> given\\.$#"
message: "#^Parameter \\$options of function Laravel\\\\Prompts\\\\select expects array\\<int\\|string, string\\>\\|Illuminate\\\\Support\\\\Collection\\<int\\|string, string\\>, Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\), class\\-string\\<Illuminate\\\\Database\\\\Eloquent\\\\Model\\>\\> given\\.$#"
count: 1
path: src/Commands/BuilderCommand.php

Expand All @@ -56,7 +56,7 @@ parameters:
path: src/Commands/FactoryCommand.php

-
message: "#^Parameter \\$options of function Laravel\\\\Prompts\\\\select expects array\\<int\\|string, string\\>\\|Illuminate\\\\Support\\\\Collection\\<int\\|string, string\\>, Illuminate\\\\Support\\\\Collection\\<int, class\\-string\\<Illuminate\\\\Database\\\\Eloquent\\\\Model\\>\\> given\\.$#"
message: "#^Parameter \\$options of function Laravel\\\\Prompts\\\\select expects array\\<int\\|string, string\\>\\|Illuminate\\\\Support\\\\Collection\\<int\\|string, string\\>, Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\), class\\-string\\<Illuminate\\\\Database\\\\Eloquent\\\\Model\\>\\> given\\.$#"
count: 1
path: src/Commands/FactoryCommand.php

Expand All @@ -76,7 +76,7 @@ parameters:
path: src/Commands/ListenerCommand.php

-
message: "#^Method Soyhuce\\\\Somake\\\\Commands\\\\ListenerCommand\\:\\:disambiguateClass\\(\\) should return string but returns int\\|string\\.$#"
message: "#^Method Soyhuce\\\\Somake\\\\Commands\\\\ListenerCommand\\:\\:disambiguateEvent\\(\\) should return string but returns int\\|string\\.$#"
count: 1
path: src/Commands/ListenerCommand.php

Expand All @@ -86,7 +86,7 @@ parameters:
path: src/Commands/ListenerCommand.php

-
message: "#^Parameter \\$options of function Laravel\\\\Prompts\\\\select expects array\\<int\\|string, string\\>\\|Illuminate\\\\Support\\\\Collection\\<int\\|string, string\\>, Illuminate\\\\Support\\\\Collection\\<int, class\\-string\\> given\\.$#"
message: "#^Parameter \\$options of function Laravel\\\\Prompts\\\\select expects array\\<int\\|string, string\\>\\|Illuminate\\\\Support\\\\Collection\\<int\\|string, string\\>, Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\), class\\-string\\> given\\.$#"
count: 1
path: src/Commands/ListenerCommand.php

Expand Down Expand Up @@ -126,7 +126,7 @@ parameters:
path: src/Commands/PolicyCommand.php

-
message: "#^Parameter \\$options of function Laravel\\\\Prompts\\\\select expects array\\<int\\|string, string\\>\\|Illuminate\\\\Support\\\\Collection\\<int\\|string, string\\>, Illuminate\\\\Support\\\\Collection\\<int, class\\-string\\<Illuminate\\\\Database\\\\Eloquent\\\\Model\\>\\> given\\.$#"
message: "#^Parameter \\$options of function Laravel\\\\Prompts\\\\select expects array\\<int\\|string, string\\>\\|Illuminate\\\\Support\\\\Collection\\<int\\|string, string\\>, Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\), class\\-string\\<Illuminate\\\\Database\\\\Eloquent\\\\Model\\>\\> given\\.$#"
count: 1
path: src/Commands/PolicyCommand.php

Expand Down Expand Up @@ -156,7 +156,7 @@ parameters:
path: src/Commands/RequestCommand.php

-
message: "#^Parameter \\$options of function Laravel\\\\Prompts\\\\select expects array\\<int\\|string, string\\>\\|Illuminate\\\\Support\\\\Collection\\<int\\|string, string\\>, Illuminate\\\\Support\\\\Collection\\<int, class\\-string\\<Spatie\\\\LaravelData\\\\Data\\>\\> given\\.$#"
message: "#^Parameter \\$options of function Laravel\\\\Prompts\\\\select expects array\\<int\\|string, string\\>\\|Illuminate\\\\Support\\\\Collection\\<int\\|string, string\\>, Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\), class\\-string\\<Spatie\\\\LaravelData\\\\Data\\>\\> given\\.$#"
count: 1
path: src/Commands/RequestCommand.php

Expand Down Expand Up @@ -191,7 +191,7 @@ parameters:
path: src/Commands/ResourceCommand.php

-
message: "#^Parameter \\$options of function Laravel\\\\Prompts\\\\select expects array\\<int\\|string, string\\>\\|Illuminate\\\\Support\\\\Collection\\<int\\|string, string\\>, Illuminate\\\\Support\\\\Collection\\<int, class\\-string\\<Illuminate\\\\Database\\\\Eloquent\\\\Model\\>\\> given\\.$#"
message: "#^Parameter \\$options of function Laravel\\\\Prompts\\\\select expects array\\<int\\|string, string\\>\\|Illuminate\\\\Support\\\\Collection\\<int\\|string, string\\>, Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\), class\\-string\\<Illuminate\\\\Database\\\\Eloquent\\\\Model\\>\\> given\\.$#"
count: 1
path: src/Commands/ResourceCommand.php

Expand Down Expand Up @@ -226,7 +226,7 @@ parameters:
path: src/Commands/TestCommand.php

-
message: "#^Parameter \\$options of function Laravel\\\\Prompts\\\\select expects array\\<int\\|string, string\\>\\|Illuminate\\\\Support\\\\Collection\\<int\\|string, string\\>, Illuminate\\\\Support\\\\Collection\\<int, class\\-string\\> given\\.$#"
message: "#^Parameter \\$options of function Laravel\\\\Prompts\\\\select expects array\\<int\\|string, string\\>\\|Illuminate\\\\Support\\\\Collection\\<int\\|string, string\\>, Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\), class\\-string\\> given\\.$#"
count: 1
path: src/Commands/TestCommand.php

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Concerns/AsksClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function disambiguateClass(Collection $guessedClasses): string

return select(
label: 'Which one should I choose ?',
options: $guessedClasses
options: $guessedClasses->keyBy(fn (string $fqcn) => $fqcn)
);
}
}
2 changes: 1 addition & 1 deletion src/Commands/Concerns/AsksData.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private function disambiguateDatas(Collection $datas): string

return select(
label: 'Which one should I choose ?',
options: $datas
options: $datas->keyBy(fn (string $fqcn) => $fqcn)
);
}
}
8 changes: 4 additions & 4 deletions src/Commands/Concerns/AsksEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function askEvent(string $question, Collection $events): string
return match ($guessedEvents->count()) {
0 => $this->qualifyEvent($question, $event),
1 => $guessedEvents->first(),
default => $this->disambiguateClass($guessedEvents)
default => $this->disambiguateEvent($guessedEvents)
};
}

Expand All @@ -71,15 +71,15 @@ private function qualifyEvent(string $question, string $event): string
}

/**
* @param \Illuminate\Support\Collection<int, class-string> $guessedClasses
* @param \Illuminate\Support\Collection<int, class-string> $guessedEvents
*/
private function disambiguateClass(Collection $guessedClasses): string
private function disambiguateEvent(Collection $guessedEvents): string
{
warning('I\'m not sure which class you choose...');

return select(
label: 'Which one should I choose ?',
options: $guessedClasses
options: $guessedEvents->keyBy(fn (string $fqcn) => $fqcn)
);
}
}
2 changes: 1 addition & 1 deletion src/Commands/Concerns/AsksModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private function disambiguateModel(Collection $models): string

return select(
label: 'Which one should I choose ?',
options: $models,
options: $models->keyBy(fn (string $fqcn) => $fqcn),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types=1);

namespace App\Admin\Controllers;

class InvokableVideoController
{
public function index(): void
{
}
}
2 changes: 2 additions & 0 deletions tests/Feature/TestCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
$this->artisan('somake:test')
->expectsQuestion('Which kind of test do you want to create ?', 'Feature')
->expectsQuestion('Which controller do you want to cover ?', 'InvokableVideoController')
->expectsOutputToContain('I\'m not sure which class you choose...')
->expectsQuestion('Which one should I choose ?', 'App\\Website\\Videos\\Controllers\\InvokableVideoController')
->expectsQuestion('Which method do you want to cover ?', '__invoke')
->expectsQuestion('What is the Test name ?', 'IndexVideosTest')
->expectsOutputToContain('The Tests\\Feature\\Website\\Videos\\InvokableVideoController\\IndexVideosTest class was successfully created !')
Expand Down

0 comments on commit f68c5ee

Please sign in to comment.