Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspertey authored and github-actions[bot] committed Oct 14, 2024
1 parent 33e906c commit c55cd08
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 84 deletions.
14 changes: 7 additions & 7 deletions config/ddd.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
],
],

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Concerns/QualifiesDomainModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Concerns/ResolvesDomainFromInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
trait ResolvesDomainFromInput
{
use CanPromptForDomain,
QualifiesDomainModels,
HandleHooks;
HandleHooks,
QualifiesDomainModels;

protected $nameIsAbsolute = false;

Expand Down
21 changes: 9 additions & 12 deletions src/Commands/DomainControllerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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)
) {
Expand Down Expand Up @@ -63,21 +60,21 @@ 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, [
'{{ storeRequest }}' => $storeRequestClass,
'{{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,
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/DomainModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
]);
Expand Down
1 change: 0 additions & 1 deletion src/Commands/Migration/BaseMigrateMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/Commands/Migration/DomainMigrateMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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';
}
}
10 changes: 5 additions & 5 deletions src/Support/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand All @@ -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
);
}
Expand Down
15 changes: 7 additions & 8 deletions src/Support/DomainAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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']);
});
}

Expand All @@ -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';
});
}

Expand All @@ -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;
Expand Down
18 changes: 2 additions & 16 deletions src/Support/DomainMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions src/Support/DomainResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Lunarstorm\LaravelDDD\Support;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;

class DomainResolver
Expand All @@ -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();
}
Expand Down
10 changes: 4 additions & 6 deletions tests/Generator/ControllerMakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -64,7 +62,7 @@

expect(file_exists($expectedPath))->toBeFalse();

Artisan::call("ddd:controller",[
Artisan::call('ddd:controller', [
'name' => $controllerName,
'--domain' => $domainName,
'--model' => $modelName,
Expand Down Expand Up @@ -117,7 +115,7 @@
}
}

Artisan::call("ddd:controller", [
Artisan::call('ddd:controller', [
'name' => $controllerName,
'--domain' => $domainName,
'--model' => $modelName,
Expand All @@ -127,7 +125,7 @@
$output = Artisan::output();

foreach ($generatedPaths as $path) {
if(Feature::IncludeFilepathInGeneratorCommandOutput->exists()){
if (Feature::IncludeFilepathInGeneratorCommandOutput->exists()) {
expect($output)->toContainFilepath($path);
}

Expand Down
20 changes: 8 additions & 12 deletions tests/Generator/MigrationMakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'),
);
Expand All @@ -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) {
Expand All @@ -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();

Expand All @@ -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');
2 changes: 1 addition & 1 deletion tests/Generator/Model/MakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit c55cd08

Please sign in to comment.