diff --git a/composer.json b/composer.json index 712e3c7..6bd153a 100644 --- a/composer.json +++ b/composer.json @@ -16,12 +16,12 @@ } ], "require": { - "illuminate/pipeline": "^6.0 || ^7.0", - "illuminate/support": "^6.0 || ^7.0", - "laravel-shift/blueprint": "^1.15.3" + "illuminate/pipeline": "^6.0 || ^7.0 || ^8.0", + "illuminate/support": "^6.0 || ^7.0 || ^8.0", + "laravel-shift/blueprint": "^1.18" }, "require-dev": { - "orchestra/testbench": "^4.0 || ^5.0", + "orchestra/testbench": "^4.0 || ^5.0 || ^6.0", "mockery/mockery": "^1.3", "phpunit/phpunit": "^9.0" }, diff --git a/src/NovaGenerator.php b/src/NovaGenerator.php index b4fd3d9..4132663 100644 --- a/src/NovaGenerator.php +++ b/src/NovaGenerator.php @@ -2,15 +2,15 @@ namespace Naoray\BlueprintNovaAddon; -use Blueprint\Tree; use Blueprint\Blueprint; +use Blueprint\Contracts\Generator; use Blueprint\Models\Model; -use Illuminate\Support\Str; +use Blueprint\Tree; use Illuminate\Pipeline\Pipeline; -use Blueprint\Contracts\Generator; +use Illuminate\Support\Str; use Naoray\BlueprintNovaAddon\Contracts\Task; -use Naoray\BlueprintNovaAddon\Tasks\RemapImports; use Naoray\BlueprintNovaAddon\Tasks\AddTimestampFields; +use Naoray\BlueprintNovaAddon\Tasks\RemapImports; class NovaGenerator implements Generator { @@ -34,13 +34,13 @@ public function output(Tree $tree): array { $output = []; - $stub = $this->files->get($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub'); + $stub = $this->files->get($this->stubPath().DIRECTORY_SEPARATOR.'class.stub'); /** @var \Blueprint\Models\Model $model */ foreach ($tree->models() as $model) { $path = $this->getPath($model); - if (!$this->files->exists(dirname($path))) { + if (! $this->files->exists(dirname($path))) { $this->files->makeDirectory(dirname($path), 0755, true); } @@ -54,9 +54,9 @@ public function output(Tree $tree): array protected function getPath(Model $model): string { - $path = str_replace('\\', '/', Blueprint::relativeNamespace($this->getNovaNamespace($model) . '/' . $model->name())); + $path = str_replace('\\', '/', Blueprint::relativeNamespace($this->getNovaNamespace($model).'/'.$model->name())); - return config('blueprint.app_path') . '/' . $path . '.php'; + return config('blueprint.app_path').'/'.$path.'.php'; } protected function populateStub(string $stub, Model $model): string @@ -72,7 +72,7 @@ protected function populateStub(string $stub, Model $model): string $stub = str_replace('DummyNamespace', $this->getNovaNamespace($model), $stub); $stub = str_replace('DummyClass', $model->name(), $stub); - $stub = str_replace('DummyModel', '\\' . $model->fullyQualifiedClassName(), $stub); + $stub = str_replace('DummyModel', '\\'.$model->fullyQualifiedClassName(), $stub); $stub = str_replace('// fields...', $data['fields'], $stub); $stub = str_replace('use Illuminate\Http\Request;', implode(PHP_EOL, $data['imports']), $stub); @@ -82,10 +82,10 @@ protected function populateStub(string $stub, Model $model): string protected function getNovaNamespace(Model $model): string { $namespace = Str::after($model->fullyQualifiedNamespace(), config('blueprint.namespace')); - $namespace = config('blueprint.namespace') . '\Nova' . $namespace; + $namespace = config('blueprint.namespace').'\Nova'.$namespace; if (config('blueprint.models_namespace')) { - $namespace = str_replace('\\' . config('blueprint.models_namespace'), '', $namespace); + $namespace = str_replace('\\'.config('blueprint.models_namespace'), '', $namespace); } return $namespace; @@ -110,7 +110,7 @@ protected function filteredTasks(): array { $tasks = $this->tasks; - if (!config('nova_blueprint.timestamps')) { + if (! config('nova_blueprint.timestamps')) { $tasks = array_filter($tasks, function ($key) { return $key !== AddTimestampFields::class; }, ARRAY_FILTER_USE_KEY); diff --git a/tests/NovaGeneratorTest.php b/tests/NovaGeneratorTest.php index ec93853..a75cfdf 100644 --- a/tests/NovaGeneratorTest.php +++ b/tests/NovaGeneratorTest.php @@ -2,14 +2,14 @@ namespace Naoray\BlueprintNovaAddon\Tests; -use Blueprint\Tree; use Blueprint\Blueprint; +use Blueprint\Tree; use Naoray\BlueprintNovaAddon\HasStubPath; use Naoray\BlueprintNovaAddon\NovaGenerator; -use Naoray\BlueprintNovaAddon\Tasks\AddRegularFields; use Naoray\BlueprintNovaAddon\Tasks\AddIdentifierField; -use Naoray\BlueprintNovaAddon\Tasks\AddTimestampFields; +use Naoray\BlueprintNovaAddon\Tasks\AddRegularFields; use Naoray\BlueprintNovaAddon\Tasks\AddRelationshipFields; +use Naoray\BlueprintNovaAddon\Tasks\AddTimestampFields; class NovaGeneratorTest extends TestCase { @@ -44,7 +44,7 @@ protected function setUp(): void public function output_generates_nothing_for_empty_tree() { $this->files->expects('get') - ->with($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub') + ->with($this->stubPath().DIRECTORY_SEPARATOR.'class.stub') ->andReturn(file_get_contents('stubs/class.stub')); $this->files->shouldNotHaveReceived('put'); @@ -59,7 +59,7 @@ public function output_generates_nothing_for_empty_tree() public function output_generates_nova_resources($definition, $path, $novaResource) { $this->files->expects('get') - ->with($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub') + ->with($this->stubPath().DIRECTORY_SEPARATOR.'class.stub') ->andReturn(file_get_contents('stubs/class.stub')); $this->files->expects('exists') @@ -81,7 +81,7 @@ public function output_generates_nova_resources($definition, $path, $novaResourc public function output_generates_relationships() { $this->files->expects('get') - ->with($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub') + ->with($this->stubPath().DIRECTORY_SEPARATOR.'class.stub') ->andReturn(file_get_contents('stubs/class.stub')); $this->files->expects('exists') @@ -106,7 +106,7 @@ public function output_respects_blueprint_configurations() $this->app['config']->set('blueprint.models_namespace', 'Models'); $this->files->expects('get') - ->with($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub') + ->with($this->stubPath().DIRECTORY_SEPARATOR.'class.stub') ->andReturn(file_get_contents('stubs/class.stub')); $this->files->expects('exists') @@ -131,7 +131,7 @@ public function output_respects_packages_configuration() $this->app['config']->set('nova_blueprint.timestamps', false); $this->files->expects('get') - ->with($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub') + ->with($this->stubPath().DIRECTORY_SEPARATOR.'class.stub') ->andReturn(file_get_contents('stubs/class.stub')); $this->files->expects('exists')