From 682a6ce656cbb7e1da404baf2f15e5e42368b68a Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 28 Sep 2023 11:07:29 +0800 Subject: [PATCH] wip Signed-off-by: Mior Muhammad Zaki --- src/Commands/GeneratorCommand.php | 9 ++++----- src/Concerns/CodeGenerator.php | 3 +-- src/Concerns/MigrationGenerator.php | 4 +--- src/Concerns/ResolvesPresetStubsOverrides.php | 3 --- src/Concerns/TestGenerator.php | 7 ++----- src/Concerns/UsingGeneratorPreset.php | 18 ++++++++++++++++++ 6 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 src/Concerns/UsingGeneratorPreset.php diff --git a/src/Commands/GeneratorCommand.php b/src/Commands/GeneratorCommand.php index 1e3830f..81582d8 100644 --- a/src/Commands/GeneratorCommand.php +++ b/src/Commands/GeneratorCommand.php @@ -2,7 +2,6 @@ namespace Orchestra\Canvas\Core\Commands; -use Illuminate\Filesystem\Filesystem; use Orchestra\Canvas\Core\Concerns; use Orchestra\Canvas\Core\Contracts\GeneratesCode; @@ -10,14 +9,14 @@ * @property string|null $name * @property string|null $description */ -abstract class GeneratorCommand extends \Illuminate\Console\GeneratorCommandd implements GeneratesCode +abstract class GeneratorCommand extends \Illuminate\Console\GeneratorCommand implements GeneratesCode { use Concerns\CodeGenerator; - use Concerns\TestGenerator; use Concerns\ResolvesPresetStubsOverrides; + use Concerns\TestGenerator; use Concerns\UsesGeneratorOverrides; - /** + /** * Execute the console command. * * @return bool|null @@ -106,7 +105,7 @@ protected function possibleEvents() * @param string $stub * @return string */ - protected function resolveStubPath(string $stub) + protected function resolveStubPath($stub) { return $this->resolveStubPathUsingCanvas($stub); } diff --git a/src/Concerns/CodeGenerator.php b/src/Concerns/CodeGenerator.php index 451309d..400f1ca 100644 --- a/src/Concerns/CodeGenerator.php +++ b/src/Concerns/CodeGenerator.php @@ -3,12 +3,11 @@ namespace Orchestra\Canvas\Core\Concerns; use Illuminate\Console\Concerns\CreatesMatchingTest; -use Illuminate\Console\Concerns\CreatesUsingGeneratorPreset; use Illuminate\Support\Str; trait CodeGenerator { - use CreatesUsingGeneratorPreset; + use UsingGeneratorPreset; /** * Generate code. diff --git a/src/Concerns/MigrationGenerator.php b/src/Concerns/MigrationGenerator.php index 1809835..185564e 100644 --- a/src/Concerns/MigrationGenerator.php +++ b/src/Concerns/MigrationGenerator.php @@ -2,11 +2,9 @@ namespace Orchestra\Canvas\Core\Concerns; -use Illuminate\Console\Concerns\CreatesUsingGeneratorPreset; - trait MigrationGenerator { - use CreatesUsingGeneratorPreset; + use UsingGeneratorPreset; /** * Create a base migration file for the table. diff --git a/src/Concerns/ResolvesPresetStubsOverrides.php b/src/Concerns/ResolvesPresetStubsOverrides.php index 459436d..b078e3f 100644 --- a/src/Concerns/ResolvesPresetStubsOverrides.php +++ b/src/Concerns/ResolvesPresetStubsOverrides.php @@ -6,9 +6,6 @@ trait ResolvesPresetStubsOverrides { /** * Resolve the fully-qualified path to the stub. - * - * @param string $stub - * @return string */ protected function resolveStubPathUsingCanvas(string $stub): string { diff --git a/src/Concerns/TestGenerator.php b/src/Concerns/TestGenerator.php index 5730591..142ddac 100644 --- a/src/Concerns/TestGenerator.php +++ b/src/Concerns/TestGenerator.php @@ -2,12 +2,11 @@ namespace Orchestra\Canvas\Core\Concerns; -use Illuminate\Console\Concerns\CreatesUsingGeneratorPreset; use Illuminate\Support\Str; trait TestGenerator { - use CreatesUsingGeneratorPreset; + use UsingGeneratorPreset; /** * Create the matching test case if requested. @@ -18,9 +17,7 @@ protected function handleTestCreationUsingCanvas(string $path): bool return false; } - $sourcePath = \in_array(CreatesUsingGeneratorPreset::class, class_uses_recursive($this)) - ? $this->generatorPreset()->sourcePath() - : $this->laravel['path']; + $sourcePath = $this->generatorPreset()->sourcePath(); return $this->call('make:test', array_merge([ 'name' => Str::of($path)->after($sourcePath)->beforeLast('.php')->append('Test')->replace('\\', '/'), diff --git a/src/Concerns/UsingGeneratorPreset.php b/src/Concerns/UsingGeneratorPreset.php new file mode 100644 index 0000000..5977c61 --- /dev/null +++ b/src/Concerns/UsingGeneratorPreset.php @@ -0,0 +1,18 @@ +generatorPreset()->sourcePath(); + } +}