diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 795b8b1..7984a94 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,10 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Call to an undefined method Illuminate\\\\Contracts\\\\Foundation\\\\Application\\:\\:joinPaths\\(\\)\\.$#" - count: 1 - path: src/Commands/MigrationGeneratorCommand.php - - message: "#^Cannot access offset 'migration\\.creator' on Illuminate\\\\Contracts\\\\Foundation\\\\Application\\.$#" count: 1 diff --git a/src/Concerns/MigrationGenerator.php b/src/Concerns/MigrationGenerator.php index 5c512f6..069409c 100644 --- a/src/Concerns/MigrationGenerator.php +++ b/src/Concerns/MigrationGenerator.php @@ -2,6 +2,8 @@ namespace Orchestra\Canvas\Core\Concerns; +use function Illuminate\Filesystem\join_paths; + trait MigrationGenerator { use CreatesUsingGeneratorPreset; @@ -22,7 +24,7 @@ protected function createBaseMigrationUsingCanvas(string $table): string protected function migrationExistsUsingCanvas(string $table): bool { return \count($this->files->glob( - $this->laravel->joinPaths($this->generatorPreset()->migrationPath(), '*_*_*_*_create_'.$table.'_table.php') + join_paths($this->generatorPreset()->migrationPath(), '*_*_*_*_create_'.$table.'_table.php') )) !== 0; } } diff --git a/src/Concerns/ResolvesPresetStubs.php b/src/Concerns/ResolvesPresetStubs.php index b2b1c94..cf8a626 100644 --- a/src/Concerns/ResolvesPresetStubs.php +++ b/src/Concerns/ResolvesPresetStubs.php @@ -2,6 +2,8 @@ namespace Orchestra\Canvas\Core\Concerns; +use function Illuminate\Filesystem\join_paths; + trait ResolvesPresetStubs { /** @@ -14,7 +16,7 @@ protected function resolveStubPath($stub) { $preset = $this->generatorPreset(); - return $preset->hasCustomStubPath() && file_exists($customPath = implode('/', [$preset->basePath(), trim($stub, '/')])) + return $preset->hasCustomStubPath() && file_exists($customPath = join_paths($preset->basePath(), trim($stub, '/'))) ? $customPath : $this->resolveDefaultStubPath($stub); } diff --git a/src/Concerns/UsesGeneratorOverrides.php b/src/Concerns/UsesGeneratorOverrides.php index cf7a22c..519e878 100644 --- a/src/Concerns/UsesGeneratorOverrides.php +++ b/src/Concerns/UsesGeneratorOverrides.php @@ -6,6 +6,8 @@ use Orchestra\Canvas\Core\Presets\Preset; use Symfony\Component\Finder\Finder; +use function Illuminate\Filesystem\join_paths; + trait UsesGeneratorOverrides { /** @@ -31,7 +33,7 @@ protected function getPathUsingCanvas(string $name): string { $name = Str::replaceFirst($this->rootNamespace(), '', $name); - return $this->getGeneratorSourcePath().'/'.str_replace('\\', '/', $name).'.php'; + return join_paths($this->getGeneratorSourcePath(), str_replace('\\', '/', $name).'.php'); } /** @@ -57,7 +59,7 @@ protected function viewPathUsingCanvas(string $path = ''): string { $views = $this->generatorPreset()->viewPath(); - return $views.($path ? DIRECTORY_SEPARATOR.$path : $path); + return join_paths($views, $path); } /** @@ -69,7 +71,7 @@ protected function possibleModelsUsingCanvas(): array { $sourcePath = $this->generatorPreset()->sourcePath(); - $modelPath = is_dir("{$sourcePath}/Models") ? "{$sourcePath}/Models" : $sourcePath; + $modelPath = is_dir(join_paths($sourcePath, 'Models')) ? join_paths($sourcePath, 'Models') : $sourcePath; return collect((new Finder)->files()->depth(0)->in($modelPath)) ->map(fn ($file) => $file->getBasename('.php')) @@ -85,7 +87,7 @@ protected function possibleModelsUsingCanvas(): array */ protected function possibleEventsUsingCanvas(): array { - $eventPath = sprintf('%s/Events', $this->generatorPreset()->sourcePath()); + $eventPath = join_paths($this->generatorPreset()->sourcePath(), 'Events'); if (! is_dir($eventPath)) { return []; diff --git a/src/Presets/Laravel.php b/src/Presets/Laravel.php index 73d5115..5c10b1e 100644 --- a/src/Presets/Laravel.php +++ b/src/Presets/Laravel.php @@ -2,6 +2,8 @@ namespace Orchestra\Canvas\Core\Presets; +use function Illuminate\Filesystem\join_paths; + class Laravel extends Preset { /** @@ -123,7 +125,7 @@ public function commandNamespace() */ public function modelNamespace() { - return is_dir("{$this->sourcePath()}/Models") ? "{$this->rootNamespace()}Models\\" : $this->rootNamespace(); + return is_dir(join_paths($this->sourcePath(), 'Models')) ? "{$this->rootNamespace()}Models\\" : $this->rootNamespace(); } /** diff --git a/tests/Commands/GeneratorCommandTest.php b/tests/Commands/GeneratorCommandTest.php index e6af20e..deff79d 100644 --- a/tests/Commands/GeneratorCommandTest.php +++ b/tests/Commands/GeneratorCommandTest.php @@ -5,8 +5,11 @@ use Orchestra\Testbench\Concerns\InteractsWithPublishedFiles; use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\TestCase; +use PHPUnit\Framework\Attributes\RequiresOperatingSystem; use PHPUnit\Framework\Attributes\Test; +use function Illuminate\Filesystem\join_paths; + class GeneratorCommandTest extends TestCase { use InteractsWithPublishedFiles; @@ -88,12 +91,24 @@ public function it_cannot_generate_class_file_given_reserved_name() } #[Test] + #[RequiresOperatingSystem('Linux|DAR')] public function it_cannot_generate_class_file_when_file_already_exist() { - file_put_contents(base_path('app/Value/Foo.php'), 'artisan('make:code', ['name' => 'Value/Foo']) ->expectsOutputToContain('class [app/Value/Foo.php] already exists!') ->assertFailed(); } + + #[Test] + #[RequiresOperatingSystem('Windows')] + public function it_cannot_generate_class_file_when_file_already_exist_on_windows() + { + file_put_contents(base_path(join_paths('app', 'Value', 'Foo.php')), 'artisan('make:code', ['name' => 'Value/Foo']) + ->expectsOutputToContain('class [app\Value\Foo.php] already exists!') + ->assertFailed(); + } }