Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Sep 28, 2023
1 parent c178fbb commit 682a6ce
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
9 changes: 4 additions & 5 deletions src/Commands/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

namespace Orchestra\Canvas\Core\Commands;

use Illuminate\Filesystem\Filesystem;
use Orchestra\Canvas\Core\Concerns;
use Orchestra\Canvas\Core\Contracts\GeneratesCode;

/**
* @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
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Concerns/CodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions src/Concerns/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions src/Concerns/ResolvesPresetStubsOverrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
7 changes: 2 additions & 5 deletions src/Concerns/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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('\\', '/'),
Expand Down
18 changes: 18 additions & 0 deletions src/Concerns/UsingGeneratorPreset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Orchestra\Canvas\Core\Concerns;

use Illuminate\Console\Concerns\CreatesUsingGeneratorPreset;

trait UsingGeneratorPreset
{
use CreatesUsingGeneratorPreset;

/**
* Get the generator preset source path.
*/
protected function getGeneratorSourcePath(): string
{
return $this->generatorPreset()->sourcePath();
}
}

0 comments on commit 682a6ce

Please sign in to comment.