diff --git a/config/ddd.php b/config/ddd.php index dda2320..030498f 100644 --- a/config/ddd.php +++ b/config/ddd.php @@ -70,14 +70,14 @@ 'trait' => '', ], -'application_layer' => [ - 'path' => 'app/Modules', - 'namespace' => 'App\Modules', - 'objects' => [ - 'controller', - 'request', + 'application_layer' => [ + 'path' => 'app/Modules', + 'namespace' => 'App\Modules', + 'objects' => [ + 'controller', + 'request', + ], ], -], /* |-------------------------------------------------------------------------- diff --git a/src/Commands/Concerns/QualifiesDomainModels.php b/src/Commands/Concerns/QualifiesDomainModels.php index 339f58f..92ad4ed 100644 --- a/src/Commands/Concerns/QualifiesDomainModels.php +++ b/src/Commands/Concerns/QualifiesDomainModels.php @@ -26,7 +26,7 @@ protected function qualifyClass($name) protected function qualifyModel(string $model) { - if($domain = $this->domain) { + if ($domain = $this->domain) { $domainModel = $domain->model($model); return $domainModel->fullyQualifiedName; diff --git a/src/Commands/Concerns/ResolvesDomainFromInput.php b/src/Commands/Concerns/ResolvesDomainFromInput.php index 2f11895..bd65dd8 100644 --- a/src/Commands/Concerns/ResolvesDomainFromInput.php +++ b/src/Commands/Concerns/ResolvesDomainFromInput.php @@ -11,8 +11,8 @@ trait ResolvesDomainFromInput { use CanPromptForDomain, - QualifiesDomainModels, - HandleHooks; + HandleHooks, + QualifiesDomainModels; protected $nameIsAbsolute = false; diff --git a/src/Commands/DomainControllerMakeCommand.php b/src/Commands/DomainControllerMakeCommand.php index dc628e6..751a303 100644 --- a/src/Commands/DomainControllerMakeCommand.php +++ b/src/Commands/DomainControllerMakeCommand.php @@ -3,18 +3,15 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Routing\Console\ControllerMakeCommand; -use Illuminate\Support\Str; use Lunarstorm\LaravelDDD\Commands\Concerns\CallsDomainCommands; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; -use Lunarstorm\LaravelDDD\Support\DomainResolver; -use Lunarstorm\LaravelDDD\Support\Path; use function Laravel\Prompts\confirm; class DomainControllerMakeCommand extends ControllerMakeCommand { - use ResolvesDomainFromInput, - CallsDomainCommands; + use CallsDomainCommands, + ResolvesDomainFromInput; protected $name = 'ddd:controller'; @@ -23,7 +20,7 @@ protected function buildModelReplacements(array $replace) $modelClass = $this->parseModel($this->option('model')); if ( - !app()->runningUnitTests() + ! app()->runningUnitTests() && ! class_exists($modelClass) && confirm("A {$modelClass} model does not exist. Do you want to generate it?", default: true) ) { @@ -63,10 +60,10 @@ protected function buildFormRequestReplacements(array $replace, $modelClass) ); } - $namespacedRequests = $namespace . '\\' . $storeRequestClass . ';'; + $namespacedRequests = $namespace.'\\'.$storeRequestClass.';'; if ($storeRequestClass !== $updateRequestClass) { - $namespacedRequests .= PHP_EOL . 'use ' . $namespace . '\\' . $updateRequestClass . ';'; + $namespacedRequests .= PHP_EOL.'use '.$namespace.'\\'.$updateRequestClass.';'; } return array_merge($replace, [ @@ -74,10 +71,10 @@ protected function buildFormRequestReplacements(array $replace, $modelClass) '{{storeRequest}}' => $storeRequestClass, '{{ updateRequest }}' => $updateRequestClass, '{{updateRequest}}' => $updateRequestClass, - '{{ namespacedStoreRequest }}' => $namespace . '\\' . $storeRequestClass, - '{{namespacedStoreRequest}}' => $namespace . '\\' . $storeRequestClass, - '{{ namespacedUpdateRequest }}' => $namespace . '\\' . $updateRequestClass, - '{{namespacedUpdateRequest}}' => $namespace . '\\' . $updateRequestClass, + '{{ namespacedStoreRequest }}' => $namespace.'\\'.$storeRequestClass, + '{{namespacedStoreRequest}}' => $namespace.'\\'.$storeRequestClass, + '{{ namespacedUpdateRequest }}' => $namespace.'\\'.$updateRequestClass, + '{{namespacedUpdateRequest}}' => $namespace.'\\'.$updateRequestClass, '{{ namespacedRequests }}' => $namespacedRequests, '{{namespacedRequests}}' => $namespacedRequests, ]); diff --git a/src/Commands/DomainModelMakeCommand.php b/src/Commands/DomainModelMakeCommand.php index 277cb97..9f798e0 100644 --- a/src/Commands/DomainModelMakeCommand.php +++ b/src/Commands/DomainModelMakeCommand.php @@ -59,7 +59,7 @@ protected function createFactory() $factory = Str::studly($this->argument('name')); $this->call(DomainFactoryMakeCommand::class, [ - 'name' => $factory . 'Factory', + 'name' => $factory.'Factory', '--domain' => $this->domain->dotName, '--model' => $this->qualifyClass($this->getNameInput()), ]); diff --git a/src/Commands/Migration/BaseMigrateMakeCommand.php b/src/Commands/Migration/BaseMigrateMakeCommand.php index d84ed3d..789192f 100644 --- a/src/Commands/Migration/BaseMigrateMakeCommand.php +++ b/src/Commands/Migration/BaseMigrateMakeCommand.php @@ -3,7 +3,6 @@ namespace Lunarstorm\LaravelDDD\Commands\Migration; use Illuminate\Database\Console\Migrations\MigrateMakeCommand; -use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; use Symfony\Component\Console\Input\InputOption; class BaseMigrateMakeCommand extends MigrateMakeCommand diff --git a/src/Commands/Migration/DomainMigrateMakeCommand.php b/src/Commands/Migration/DomainMigrateMakeCommand.php index 61f5115..e0dcb73 100644 --- a/src/Commands/Migration/DomainMigrateMakeCommand.php +++ b/src/Commands/Migration/DomainMigrateMakeCommand.php @@ -2,9 +2,8 @@ namespace Lunarstorm\LaravelDDD\Commands\Migration; -use Lunarstorm\LaravelDDD\Support\Path; use Lunarstorm\LaravelDDD\Commands\Concerns\ResolvesDomainFromInput; -use Lunarstorm\LaravelDDD\Commands\Migration\BaseMigrateMakeCommand; +use Lunarstorm\LaravelDDD\Support\Path; class DomainMigrateMakeCommand extends BaseMigrateMakeCommand { @@ -23,6 +22,6 @@ protected function getMigrationPath() return $this->laravel->basePath($this->domain->migrationPath); } - return $this->laravel->databasePath() . DIRECTORY_SEPARATOR . 'migrations'; + return $this->laravel->databasePath().DIRECTORY_SEPARATOR.'migrations'; } } diff --git a/src/Support/Domain.php b/src/Support/Domain.php index 7e8c3b8..eb3fd32 100644 --- a/src/Support/Domain.php +++ b/src/Support/Domain.php @@ -45,7 +45,7 @@ public function __construct(string $domain, ?string $subdomain = null) $subdomain = str($subdomain)->trim('\\/')->toString(); $this->domainWithSubdomain = str($domain) - ->when($subdomain, fn($domain) => $domain->append("\\{$subdomain}")) + ->when($subdomain, fn ($domain) => $domain->append("\\{$subdomain}")) ->toString(); $this->domain = $domain; @@ -115,7 +115,7 @@ public function guessNamespaceFromName(string $name): string return str($name) ->before($baseName) ->trim('\\') - ->prepend(DomainResolver::domainRootNamespace() . '\\' . $this->domainWithSubdomain . '\\') + ->prepend(DomainResolver::domainRootNamespace().'\\'.$this->domainWithSubdomain.'\\') ->toString(); } @@ -136,10 +136,10 @@ public function object(string $type, string $name, bool $absolute = false): Doma name: $baseName, domain: $this->domain, namespace: $namespace, - fullyQualifiedName: $namespace . '\\' . $baseName, + fullyQualifiedName: $namespace.'\\'.$baseName, path: DomainResolver::isApplicationLayer($type) - ? $this->pathInApplicationLayer($namespace . '\\' . $baseName) - : $this->path($namespace . '\\' . $baseName), + ? $this->pathInApplicationLayer($namespace.'\\'.$baseName) + : $this->path($namespace.'\\'.$baseName), type: $type ); } diff --git a/src/Support/DomainAutoloader.php b/src/Support/DomainAutoloader.php index e125286..9e812d9 100644 --- a/src/Support/DomainAutoloader.php +++ b/src/Support/DomainAutoloader.php @@ -9,7 +9,6 @@ use Illuminate\Foundation\Application; use Illuminate\Support\Arr; use Illuminate\Support\Collection; -use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Gate; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; @@ -51,7 +50,7 @@ public function autoload(): void protected static function normalizePaths($path): array { return collect($path) - ->filter(fn($path) => is_dir($path)) + ->filter(fn ($path) => is_dir($path)) ->toArray(); } @@ -100,10 +99,10 @@ protected function handlePolicies(): void return Arr::wrap(Collection::times(count($classDirnameSegments), function ($index) use ($class, $classDirnameSegments) { $classDirname = implode('\\', array_slice($classDirnameSegments, 0, $index)); - return $classDirname . '\\Policies\\' . class_basename($class) . 'Policy'; + return $classDirname.'\\Policies\\'.class_basename($class).'Policy'; })->reverse()->values()->first(function ($class) { return class_exists($class); - }) ?: [$classDirname . '\\Policies\\' . class_basename($class) . 'Policy']); + }) ?: [$classDirname.'\\Policies\\'.class_basename($class).'Policy']); }); } @@ -116,11 +115,11 @@ protected function handleFactories(): void $appNamespace = static::appNamespace(); - $modelName = Str::startsWith($modelName, $appNamespace . 'Models\\') - ? Str::after($modelName, $appNamespace . 'Models\\') + $modelName = Str::startsWith($modelName, $appNamespace.'Models\\') + ? Str::after($modelName, $appNamespace.'Models\\') : Str::after($modelName, $appNamespace); - return 'Database\\Factories\\' . $modelName . 'Factory'; + return 'Database\\Factories\\'.$modelName.'Factory'; }); } @@ -133,7 +132,7 @@ protected static function finder($paths) ->finish('/'); $ignoredFolders = collect(config('ddd.autoload_ignore', [])) - ->map(fn($path) => Str::finish($path, '/')); + ->map(fn ($path) => Str::finish($path, '/')); if ($pathAfterDomain->startsWith($ignoredFolders)) { return false; diff --git a/src/Support/DomainMigration.php b/src/Support/DomainMigration.php index d81f6fd..91e4a65 100644 --- a/src/Support/DomainMigration.php +++ b/src/Support/DomainMigration.php @@ -2,24 +2,10 @@ namespace Lunarstorm\LaravelDDD\Support; -use Illuminate\Console\Application as ConsoleApplication; -use Illuminate\Console\Command; -use Illuminate\Container\Container; -use Illuminate\Database\Eloquent\Factories\Factory; -use Illuminate\Database\Migrations\Migration; -use Illuminate\Foundation\Application; -use Illuminate\Support\Arr; -use Illuminate\Support\Collection; -use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Gate; -use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; use Lorisleiva\Lody\Lody; -use Lunarstorm\LaravelDDD\Factories\DomainFactory; -use Lunarstorm\LaravelDDD\ValueObjects\DomainObject; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; -use Throwable; class DomainMigration { @@ -48,7 +34,7 @@ public static function paths(): array protected static function normalizePaths($path): array { return collect($path) - ->filter(fn($path) => is_dir($path)) + ->filter(fn ($path) => is_dir($path)) ->toArray(); } @@ -71,7 +57,7 @@ public static function discoverPaths(): array $finder = static::finder($paths); return Lody::filesFromFinder($finder) - ->map(fn($file) => $file->getPath()) + ->map(fn ($file) => $file->getPath()) ->unique() ->values() ->toArray(); diff --git a/src/Support/DomainResolver.php b/src/Support/DomainResolver.php index 8b1d998..a7423f3 100644 --- a/src/Support/DomainResolver.php +++ b/src/Support/DomainResolver.php @@ -2,7 +2,6 @@ namespace Lunarstorm\LaravelDDD\Support; -use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Str; class DomainResolver @@ -12,10 +11,10 @@ class DomainResolver */ public static function domainChoices(): array { - $folders = glob(app()->basePath(static::domainPath() . '/*'), GLOB_ONLYDIR); + $folders = glob(app()->basePath(static::domainPath().'/*'), GLOB_ONLYDIR); return collect($folders) - ->map(fn($path) => basename($path)) + ->map(fn ($path) => basename($path)) ->sort() ->toArray(); } diff --git a/tests/Generator/ControllerMakeTest.php b/tests/Generator/ControllerMakeTest.php index af3e8e5..a4658f4 100644 --- a/tests/Generator/ControllerMakeTest.php +++ b/tests/Generator/ControllerMakeTest.php @@ -2,9 +2,7 @@ use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Config; -use Laravel\Prompts\Prompt; use Lunarstorm\LaravelDDD\Tests\Fixtures\Enums\Feature; -use Mockery\Mock; beforeEach(function () { Config::set('ddd.domain_path', 'src/Domain'); @@ -32,7 +30,7 @@ expect($output = Artisan::output())->when( Feature::IncludeFilepathInGeneratorCommandOutput->exists(), - fn($output) => $output->toContainFilepath($relativePath), + fn ($output) => $output->toContainFilepath($relativePath), ); expect(file_exists($expectedPath))->toBeTrue(); @@ -64,7 +62,7 @@ expect(file_exists($expectedPath))->toBeFalse(); - Artisan::call("ddd:controller",[ + Artisan::call('ddd:controller', [ 'name' => $controllerName, '--domain' => $domainName, '--model' => $modelName, @@ -117,7 +115,7 @@ } } - Artisan::call("ddd:controller", [ + Artisan::call('ddd:controller', [ 'name' => $controllerName, '--domain' => $domainName, '--model' => $modelName, @@ -127,7 +125,7 @@ $output = Artisan::output(); foreach ($generatedPaths as $path) { - if(Feature::IncludeFilepathInGeneratorCommandOutput->exists()){ + if (Feature::IncludeFilepathInGeneratorCommandOutput->exists()) { expect($output)->toContainFilepath($path); } diff --git a/tests/Generator/MigrationMakeTest.php b/tests/Generator/MigrationMakeTest.php index fdf285e..adfdf57 100644 --- a/tests/Generator/MigrationMakeTest.php +++ b/tests/Generator/MigrationMakeTest.php @@ -3,9 +3,6 @@ use Illuminate\Support\Arr; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Config; -use Illuminate\Support\Str; -use Lunarstorm\LaravelDDD\Support\Domain; -use Lunarstorm\LaravelDDD\Support\DomainAutoloader; use Lunarstorm\LaravelDDD\Support\DomainCache; use Lunarstorm\LaravelDDD\Support\DomainMigration; use Lunarstorm\LaravelDDD\Support\Path; @@ -41,7 +38,7 @@ expect($output = Artisan::output())->when( Feature::IncludeFilepathInGeneratorCommandOutput->exists(), - fn($output) => $output + fn ($output) => $output ->toContainFilepath($relativePath) ->toContain('_create_invoices_table.php'), ); @@ -53,7 +50,7 @@ expect($createdMigrationFile)->toEndWith('_create_invoices_table.php'); expect(file_get_contents($createdMigrationFile)) - ->toContain("return new class extends Migration"); + ->toContain('return new class extends Migration'); })->with('domainPaths'); it('discovers domain migration folders', function ($domainPath, $domainRoot) { @@ -64,12 +61,11 @@ expect($discoveredPaths)->toHaveCount(0); - Artisan::call("ddd:migration Invoicing:" . uniqid('migration')); - Artisan::call("ddd:migration Shared:" . uniqid('migration')); - Artisan::call("ddd:migration Reporting:" . uniqid('migration')); - Artisan::call("ddd:migration Reporting:" . uniqid('migration')); - Artisan::call("ddd:migration Reporting:" . uniqid('migration')); - + Artisan::call('ddd:migration Invoicing:'.uniqid('migration')); + Artisan::call('ddd:migration Shared:'.uniqid('migration')); + Artisan::call('ddd:migration Reporting:'.uniqid('migration')); + Artisan::call('ddd:migration Reporting:'.uniqid('migration')); + Artisan::call('ddd:migration Reporting:'.uniqid('migration')); $discoveredPaths = DomainMigration::discoverPaths(); @@ -83,6 +79,6 @@ foreach ($discoveredPaths as $path) { expect(str($path)->contains($expectedFolderPatterns)) - ->toBeTrue("Expecting path to contain one of the expected folder patterns"); + ->toBeTrue('Expecting path to contain one of the expected folder patterns'); } })->with('domainPaths'); diff --git a/tests/Generator/Model/MakeTest.php b/tests/Generator/Model/MakeTest.php index 4f4bce1..f465263 100644 --- a/tests/Generator/Model/MakeTest.php +++ b/tests/Generator/Model/MakeTest.php @@ -31,7 +31,7 @@ expect(Artisan::output())->when( Feature::IncludeFilepathInGeneratorCommandOutput->exists(), - fn($output) => $output->toContainFilepath($relativePath), + fn ($output) => $output->toContainFilepath($relativePath), ); expect(file_exists($expectedModelPath))->toBeTrue(); diff --git a/tests/Generator/Model/MakeWithControllerTest.php b/tests/Generator/Model/MakeWithControllerTest.php index 52d68fb..629933f 100644 --- a/tests/Generator/Model/MakeWithControllerTest.php +++ b/tests/Generator/Model/MakeWithControllerTest.php @@ -4,7 +4,6 @@ use Illuminate\Support\Facades\Config; use Lunarstorm\LaravelDDD\Models\DomainModel; use Lunarstorm\LaravelDDD\Support\Domain; -use Lunarstorm\LaravelDDD\Support\Path; use Lunarstorm\LaravelDDD\Tests\Fixtures\Enums\Feature; beforeEach(function () { @@ -53,7 +52,7 @@ 'RecordController', [ 'src/Domain/Invoicing/Models/Record.php', - 'app/Modules/Invoicing/Controllers/RecordController.php' + 'app/Modules/Invoicing/Controllers/RecordController.php', ], ], @@ -63,7 +62,7 @@ 'RecordEntryController', [ 'src/Domain/Invoicing/Models/RecordEntry.php', - 'app/Modules/Invoicing/Controllers/RecordEntryController.php' + 'app/Modules/Invoicing/Controllers/RecordEntryController.php', ], ], @@ -73,7 +72,7 @@ 'ReportSubmissionController', [ 'src/Domain/Reporting/Internal/Models/ReportSubmission.php', - 'app/Modules/Reporting/Internal/Controllers/ReportSubmissionController.php' + 'app/Modules/Reporting/Internal/Controllers/ReportSubmissionController.php', ], ], diff --git a/tests/Generator/RequestMakeTest.php b/tests/Generator/RequestMakeTest.php index 9d2ad9a..2872b79 100644 --- a/tests/Generator/RequestMakeTest.php +++ b/tests/Generator/RequestMakeTest.php @@ -30,7 +30,7 @@ expect($output = Artisan::output())->when( Feature::IncludeFilepathInGeneratorCommandOutput->exists(), - fn($output) => $output->toContainFilepath($relativePath), + fn ($output) => $output->toContainFilepath($relativePath), ); expect(file_exists($expectedPath))->toBeTrue(); diff --git a/tests/Support/DomainTest.php b/tests/Support/DomainTest.php index d2398d1..459af6f 100644 --- a/tests/Support/DomainTest.php +++ b/tests/Support/DomainTest.php @@ -115,7 +115,7 @@ it('normalizes slashes in nested objects', function ($nameInput, $normalized) { expect((new Domain('Invoicing'))->object('class', $nameInput)) - ->name->toBe($normalized); + ->name->toBe($normalized); })->with([ ['Nested\\Thing', 'Nested\\Thing'], ['Nested/Thing', 'Nested\\Thing'],