diff --git a/database/migrations/2022_11_17_000001_create_cars_table.php b/database/migrations/2022_11_17_000001_create_cars_table.php index ed0635f..c047b99 100644 --- a/database/migrations/2022_11_17_000001_create_cars_table.php +++ b/database/migrations/2022_11_17_000001_create_cars_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/2022_11_17_000001_create_phones_table.php b/database/migrations/2022_11_17_000001_create_phones_table.php index 4dbcdb0..f4bb636 100644 --- a/database/migrations/2022_11_17_000001_create_phones_table.php +++ b/database/migrations/2022_11_17_000001_create_phones_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/2022_11_17_000002_create_mechanics_table.php b/database/migrations/2022_11_17_000002_create_mechanics_table.php index aad46ec..9da407a 100644 --- a/database/migrations/2022_11_17_000002_create_mechanics_table.php +++ b/database/migrations/2022_11_17_000002_create_mechanics_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/2022_11_17_000003_create_owners_table.php b/database/migrations/2022_11_17_000003_create_owners_table.php index 6ce41cc..3fc5c21 100644 --- a/database/migrations/2022_11_17_000003_create_owners_table.php +++ b/database/migrations/2022_11_17_000003_create_owners_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/2022_12_07_000004_add_teams_fields.php b/database/migrations/2022_12_07_000004_add_teams_fields.php index bd8d877..248863c 100644 --- a/database/migrations/2022_12_07_000004_add_teams_fields.php +++ b/database/migrations/2022_12_07_000004_add_teams_fields.php @@ -6,7 +6,8 @@ use Illuminate\Support\Facades\Schema; use Spatie\Permission\PermissionRegistrar; -return new class extends Migration { +return new class extends Migration +{ /** * Run the migrations. * @@ -18,7 +19,7 @@ public function up() $tableNames = config('permission.table_names'); $columnNames = config('permission.column_names'); - if (!$teams) { + if (! $teams) { return; } if (empty($tableNames)) { @@ -28,7 +29,7 @@ public function up() throw new \Exception('Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.'); } - if (!Schema::hasColumn($tableNames['roles'], $columnNames['team_foreign_key'])) { + if (! Schema::hasColumn($tableNames['roles'], $columnNames['team_foreign_key'])) { Schema::table($tableNames['roles'], function (Blueprint $table) use ($columnNames) { $table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable()->after('id'); $table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index'); @@ -38,7 +39,7 @@ public function up() }); } - if (!Schema::hasColumn($tableNames['model_has_permissions'], $columnNames['team_foreign_key'])) { + if (! Schema::hasColumn($tableNames['model_has_permissions'], $columnNames['team_foreign_key'])) { Schema::table($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames) { $table->unsignedBigInteger($columnNames['team_foreign_key'])->default('1'); $table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index'); @@ -57,9 +58,9 @@ public function up() }); } - if (!Schema::hasColumn($tableNames['model_has_roles'], $columnNames['team_foreign_key'])) { + if (! Schema::hasColumn($tableNames['model_has_roles'], $columnNames['team_foreign_key'])) { Schema::table($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames) { - $table->unsignedBigInteger($columnNames['team_foreign_key'])->default('1');; + $table->unsignedBigInteger($columnNames['team_foreign_key'])->default('1'); $table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index'); if (DB::getDriverName() !== 'sqlite') { @@ -88,6 +89,5 @@ public function up() */ public function down() { - } }; diff --git a/database/migrations/2022_12_07_000005_create_permission_tables.php b/database/migrations/2022_12_07_000005_create_permission_tables.php index 283c665..e31387f 100644 --- a/database/migrations/2022_12_07_000005_create_permission_tables.php +++ b/database/migrations/2022_12_07_000005_create_permission_tables.php @@ -5,7 +5,8 @@ use Illuminate\Support\Facades\Schema; use Spatie\Permission\PermissionRegistrar; -return new class extends Migration { +return new class extends Migration +{ /** * Run the migrations. * @@ -70,7 +71,6 @@ public function up() $table->primary([PermissionRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_permission_model_type_primary'); } - }); Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames, $teams) { @@ -137,4 +137,4 @@ public function down() Schema::drop($tableNames['roles']); Schema::drop($tableNames['permissions']); } -}; \ No newline at end of file +}; diff --git a/database/migrations/2022_12_09_000006_create_posts_table.php b/database/migrations/2022_12_09_000006_create_posts_table.php index c084921..66d878b 100644 --- a/database/migrations/2022_12_09_000006_create_posts_table.php +++ b/database/migrations/2022_12_09_000006_create_posts_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/2022_12_09_000007_create_comments_table.php b/database/migrations/2022_12_09_000007_create_comments_table.php index 16d1f04..078fd48 100644 --- a/database/migrations/2022_12_09_000007_create_comments_table.php +++ b/database/migrations/2022_12_09_000007_create_comments_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/2022_12_09_000007_create_images_table.php b/database/migrations/2022_12_09_000007_create_images_table.php index 7ca24b5..9f0aad1 100644 --- a/database/migrations/2022_12_09_000007_create_images_table.php +++ b/database/migrations/2022_12_09_000007_create_images_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/routes/web.php b/routes/web.php index ad6faf0..7dd6761 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,7 +3,7 @@ use Illuminate\Support\Facades\Route; use Recca0120\LaravelErd\Http\Controllers\LaravelErdController; -Route::get(config('laravel-erd.uri') . '/{file?}', [LaravelErdController::class, 'index']) +Route::get(config('laravel-erd.uri').'/{file?}', [LaravelErdController::class, 'index']) ->name('laravel-erd.show') ->middleware(config('laravel-erd.middleware')) - ->where('file', '.*'); \ No newline at end of file + ->where('file', '.*'); diff --git a/src/Console/Commands/LaravelErdCommand.php b/src/Console/Commands/LaravelErdCommand.php index 9bbae7b..0d288e2 100644 --- a/src/Console/Commands/LaravelErdCommand.php +++ b/src/Console/Commands/LaravelErdCommand.php @@ -52,10 +52,10 @@ private function setConnection(string $connection): void { config( collect(Arr::dot(config()->all())) - ->filter(fn($value, $key) => $value && Str::endsWith($key, 'database.connection')) - ->map(fn() => $connection) + ->filter(fn ($value, $key) => $value && Str::endsWith($key, 'database.connection')) + ->map(fn () => $connection) ->merge(['database.default' => $connection]) ->toArray() ); } -} \ No newline at end of file +} diff --git a/src/Console/Commands/LaravelErdInitCommand.php b/src/Console/Commands/LaravelErdInitCommand.php index edd5b5b..5e94aa2 100644 --- a/src/Console/Commands/LaravelErdInitCommand.php +++ b/src/Console/Commands/LaravelErdInitCommand.php @@ -27,7 +27,6 @@ public function handle(): int return self::FAILURE; } - } /** @@ -49,7 +48,6 @@ private function downloadDot(string $os, string $arch, string $path): void $this->download($url, $path); } - /** * @throws RequestException */ @@ -59,7 +57,7 @@ private function download(string $url, string $path): void return; } - $this->line('download: ' . $url); + $this->line('download: '.$url); File::ensureDirectoryExists(dirname($path)); File::put($path, Http::timeout(300)->get($url)->throw()->body()); File::chmod($path, 0777); @@ -67,9 +65,9 @@ private function download(string $url, string $path): void private function arch(): string { - $name = php_uname("m"); + $name = php_uname('m'); - if (false !== stripos($name, "aarch64") || false !== stripos($name, "arm64")) { + if (false !== stripos($name, 'aarch64') || false !== stripos($name, 'arm64')) { return 'arm'; } @@ -93,5 +91,4 @@ private function os(): string return 'linux'; } - -} \ No newline at end of file +} diff --git a/src/ErdFinder.php b/src/ErdFinder.php index 41621a5..10bb40a 100644 --- a/src/ErdFinder.php +++ b/src/ErdFinder.php @@ -8,16 +8,18 @@ class ErdFinder { private AbstractSchemaManager $schemaManager; + private ModelFinder $modelFinder; + private RelationFinder $relationFinder; + private string $directory; public function __construct( AbstractSchemaManager $schemaManager, - ModelFinder $modelFinder, - RelationFinder $relationFinder - ) - { + ModelFinder $modelFinder, + RelationFinder $relationFinder + ) { $this->schemaManager = $schemaManager; $this->modelFinder = $modelFinder; $this->relationFinder = $relationFinder; @@ -31,8 +33,8 @@ public function in(string $directory): ErdFinder } /** - * @param string|string[] $patterns - * @param string[] $excludes + * @param string|string[] $patterns + * @param string[] $excludes * @return Collection */ public function find($patterns = '*.php', array $excludes = []): Collection @@ -43,8 +45,8 @@ public function find($patterns = '*.php', array $excludes = []): Collection } /** - * @param string|string[] $file - * @param string[] $excludes + * @param string|string[] $file + * @param string[] $excludes * @return Collection */ public function findByFile($file, array $excludes = []): Collection @@ -55,8 +57,8 @@ public function findByFile($file, array $excludes = []): Collection } /** - * @param string $className - * @param string[] $excludes + * @param string $className + * @param string[] $excludes * @return Collection */ public function findByModel(string $className, array $excludes = []): Collection @@ -65,38 +67,38 @@ public function findByModel(string $className, array $excludes = []): Collection } /** - * @param Collection $models - * @param string[] $excludes + * @param Collection $models + * @param string[] $excludes * @return Collection */ private function findByModels(Collection $models, array $excludes = []): Collection { $missing = $models - ->flatMap(fn(string $model) => $this->relationFinder->generate($model)->collapse()) - ->map(fn(Relation $relation) => $relation->related()) + ->flatMap(fn (string $model) => $this->relationFinder->generate($model)->collapse()) + ->map(fn (Relation $relation) => $relation->related()) ->filter() ->diff($models); return $models ->merge($missing) - ->flatMap(fn(string $model) => $this->relationFinder->generate($model)->collapse()) - ->flatMap(fn(Relation $relation) => [$relation, $relation->relatedRelation()]) - ->reject(fn(Relation $relation) => $relation->includes($excludes)) - ->sortBy(fn(Relation $relation) => $this->uniqueRelation($relation)) - ->unique(fn(Relation $relation) => $this->uniqueRelation($relation)) - ->groupBy(fn(Relation $relation) => $relation->table()) - ->sortBy(fn(Collection $relations, string $table) => $table) + ->flatMap(fn (string $model) => $this->relationFinder->generate($model)->collapse()) + ->flatMap(fn (Relation $relation) => [$relation, $relation->relatedRelation()]) + ->reject(fn (Relation $relation) => $relation->includes($excludes)) + ->sortBy(fn (Relation $relation) => $this->uniqueRelation($relation)) + ->unique(fn (Relation $relation) => $this->uniqueRelation($relation)) + ->groupBy(fn (Relation $relation) => $relation->table()) + ->sortBy(fn (Collection $relations, string $table) => $table) ->map(function (Collection $relations, $table) { return new Table($this->schemaManager->introspectTable($table), $relations); }); } /** - * @param Relation $relation + * @param Relation $relation * @return string[] */ private function uniqueRelation(Relation $relation): array { return [$relation->type(), $relation->localKey(), $relation->foreignKey()]; } -} \ No newline at end of file +} diff --git a/src/Helpers.php b/src/Helpers.php index 3cd6926..9d8caa9 100644 --- a/src/Helpers.php +++ b/src/Helpers.php @@ -28,5 +28,4 @@ public static function getColumnType(Column $column): string return 'unknown'; } } - -} \ No newline at end of file +} diff --git a/src/Http/Controllers/LaravelErdController.php b/src/Http/Controllers/LaravelErdController.php index a1417c6..5e682e8 100644 --- a/src/Http/Controllers/LaravelErdController.php +++ b/src/Http/Controllers/LaravelErdController.php @@ -12,12 +12,12 @@ public function index(string $file = 'laravel-erd.sql'): View { $storagePath = config('laravel-erd.storage_path'); $extension = substr($file, strrpos($file, '.') + 1); - $path = $storagePath . '/' . $file; + $path = $storagePath.'/'.$file; abort_unless(File::exists($path), 404); $view = $extension === 'svg' ? 'svg' : 'vuerd'; - return view('laravel-erd::' . $view, ['path' => $path]); + return view('laravel-erd::'.$view, ['path' => $path]); } -} \ No newline at end of file +} diff --git a/src/LaravelErdServiceProvider.php b/src/LaravelErdServiceProvider.php index 2485f35..2da2df6 100644 --- a/src/LaravelErdServiceProvider.php +++ b/src/LaravelErdServiceProvider.php @@ -45,4 +45,4 @@ public function register() LaravelErdCommand::class, ]); } -} \ No newline at end of file +} diff --git a/src/ModelFinder.php b/src/ModelFinder.php index 946a59e..67fcbf0 100644 --- a/src/ModelFinder.php +++ b/src/ModelFinder.php @@ -28,8 +28,8 @@ public function __construct() } /** - * @param string $directory - * @param string|string[] $patterns + * @param string $directory + * @param string|string[] $patterns * @return Collection */ public function find(string $directory, $patterns = '*.php'): Collection @@ -37,9 +37,9 @@ public function find(string $directory, $patterns = '*.php'): Collection $files = Finder::create()->files()->name($patterns)->in($directory); return collect($files) - ->map(fn(SplFileInfo $file) => $this->getFullyQualifiedClassName($file)) - ->filter(fn($className) => !empty($className)) - ->filter(fn(string $className) => $this->isEloquentModel($className)) + ->map(fn (SplFileInfo $file) => $this->getFullyQualifiedClassName($file)) + ->filter(fn ($className) => ! empty($className)) + ->filter(fn (string $className) => $this->isEloquentModel($className)) ->values(); } @@ -48,7 +48,7 @@ private function isEloquentModel(string $className): bool try { return $className && is_subclass_of($className, Model::class) && - !(new ReflectionClass($className))->isAbstract(); + ! (new ReflectionClass($className))->isAbstract(); } catch (Throwable $e) { return false; } @@ -62,16 +62,15 @@ private function getFullyQualifiedClassName(SplFileInfo $file): ?string $nodes = $nodeTraverser->traverse($parser->parse($file->getContents())); /** @var ?Namespace_ $rootNode */ - $rootNode = collect($nodes)->first(fn(Node $node) => $node instanceof Namespace_); + $rootNode = collect($nodes)->first(fn (Node $node) => $node instanceof Namespace_); - if (!$rootNode) { + if (! $rootNode) { return null; } return collect($rootNode->stmts) - ->filter(static fn(Stmt $stmt) => $stmt instanceof Class_) - ->map(static fn(Class_ $stmt) => $stmt->namespacedName->toString()) + ->filter(static fn (Stmt $stmt) => $stmt instanceof Class_) + ->map(static fn (Class_ $stmt) => $stmt->namespacedName->toString()) ->first(); } - -} \ No newline at end of file +} diff --git a/src/Pivot.php b/src/Pivot.php index fc28183..19f9a53 100644 --- a/src/Pivot.php +++ b/src/Pivot.php @@ -2,7 +2,6 @@ namespace Recca0120\LaravelErd; - class Pivot { /** @@ -55,4 +54,4 @@ public function toArray(): array { return $this->attributes; } -} \ No newline at end of file +} diff --git a/src/Relation.php b/src/Relation.php index c866536..9a21aa3 100644 --- a/src/Relation.php +++ b/src/Relation.php @@ -58,7 +58,7 @@ public function pivot(): ?Pivot } /** - * @param string[] $tables + * @param string[] $tables * @return bool */ public function includes(array $tables): bool @@ -101,4 +101,4 @@ public function order(): int return 3; } -} \ No newline at end of file +} diff --git a/src/RelationFinder.php b/src/RelationFinder.php index 9ac73a5..8543707 100644 --- a/src/RelationFinder.php +++ b/src/RelationFinder.php @@ -21,8 +21,9 @@ class RelationFinder { /** - * @param class-string $className + * @param class-string $className * @return Collection|null> + * * @throws ReflectionException */ public function generate(string $className): Collection @@ -32,14 +33,14 @@ public function generate(string $className): Collection return collect($class->getMethods(ReflectionMethod::IS_PUBLIC)) ->merge($this->getTraitMethods($class)) - ->reject(fn(ReflectionMethod $method) => $method->class !== $className || $method->getNumberOfParameters() > 0) - ->mapWithKeys(fn(ReflectionMethod $method) => [$method->getName() => $this->findRelations($method, $model)]) + ->reject(fn (ReflectionMethod $method) => $method->class !== $className || $method->getNumberOfParameters() > 0) + ->mapWithKeys(fn (ReflectionMethod $method) => [$method->getName() => $this->findRelations($method, $model)]) ->filter(); } /** - * @param ReflectionMethod $method - * @param Model $model + * @param ReflectionMethod $method + * @param Model $model * @return ?Collection */ private function findRelations(ReflectionMethod $method, Model $model): ?Collection @@ -74,9 +75,9 @@ private function findRelations(ReflectionMethod $method, Model $model): ?Collect } /** - * @param BelongsToMany $return - * @param string $type - * @param string $related + * @param BelongsToMany $return + * @param string $type + * @param string $related * @return Collection */ private function belongsToMany(BelongsToMany $return, string $type, string $related): Collection @@ -121,13 +122,12 @@ private function belongsToMany(BelongsToMany $return, string $type, string $rela 'foreign_key' => $return->getQualifiedForeignPivotKeyName(), 'pivot' => new Pivot($pivot), ]); - } /** - * @param BelongsTo $return - * @param string $type - * @param string $related + * @param BelongsTo $return + * @param string $type + * @param string $related * @return ?Collection */ private function belongsTo(BelongsTo $return, string $type, string $related): ?Collection @@ -158,9 +158,9 @@ private function belongsTo(BelongsTo $return, string $type, string $related): ?C } /** - * @param HasOneOrMany $return - * @param string $type - * @param string $related + * @param HasOneOrMany $return + * @param string $type + * @param string $related * @return ?Collection */ private function hasOneOrMany(HasOneOrMany $return, string $type, string $related): ?Collection @@ -195,18 +195,18 @@ private function hasOneOrMany(HasOneOrMany $return, string $type, string $relate } /** - * @param ReflectionClass $class + * @param ReflectionClass $class * @return Collection */ private function getTraitMethods(ReflectionClass $class): Collection { return collect($class->getTraits())->flatMap( - static fn(ReflectionClass $trait) => $trait->getMethods(ReflectionMethod::IS_PUBLIC) + static fn (ReflectionClass $trait) => $trait->getMethods(ReflectionMethod::IS_PUBLIC) ); } /** - * @param string[] $attributes + * @param string[] $attributes * @return Collection */ private function makeRelation(array $attributes): Collection @@ -222,4 +222,4 @@ private function makeRelation(array $attributes): Collection return $relations; } -} \ No newline at end of file +} diff --git a/src/Table.php b/src/Table.php index 8724e79..3a8d0bf 100644 --- a/src/Table.php +++ b/src/Table.php @@ -9,6 +9,7 @@ class Table { private DBALTable $table; + /** * @var Collection */ @@ -54,4 +55,4 @@ public function relations(): Collection { return $this->relations; } -} \ No newline at end of file +} diff --git a/src/Templates/DDL.php b/src/Templates/DDL.php index 3f04109..bdd11da 100644 --- a/src/Templates/DDL.php +++ b/src/Templates/DDL.php @@ -14,7 +14,7 @@ class DDL implements Template public function render(Collection $tables): string { return $tables - ->map(fn(Table $table) => sprintf( + ->map(fn (Table $table) => sprintf( "CREATE TABLE %s (\n%s\n)", $table->name(), $this->renderColumn($table) @@ -25,7 +25,7 @@ public function render(Collection $tables): string public function save(string $output, string $path, array $options = []): int { - return (int)File::put($path, $output); + return (int) File::put($path, $output); } private function renderColumn(Table $table): string @@ -39,7 +39,7 @@ private function renderColumn(Table $table): string return implode(' ', array_filter([ $column->getName(), - $type . ($precision ? "({$precision})" : ''), + $type.($precision ? "({$precision})" : ''), $column->getNotnull() ? 'NOT NULL' : '', $default ? "DEFAULT {$default}" : '', $comment ? "COMMENT {$comment}" : '', @@ -48,12 +48,12 @@ private function renderColumn(Table $table): string }) ->merge($this->renderPrimaryKeys($table)) ->filter() - ->map(fn(string $line) => ' ' . $line) + ->map(fn (string $line) => ' '.$line) ->implode(",\n"); } /** - * @param Table $table + * @param Table $table * @return string[] */ private function renderPrimaryKeys(Table $table): array @@ -64,16 +64,16 @@ private function renderPrimaryKeys(Table $table): array } /** - * @param Collection $tables + * @param Collection $tables * @return Collection */ private function renderRelations(Collection $tables): Collection { return $tables - ->map(fn(Table $table) => $table->relations()) + ->map(fn (Table $table) => $table->relations()) ->collapse() - ->unique(fn(Relation $relation) => $relation->uniqueId()) - ->map(fn(Relation $relation) => $this->renderRelation($relation)) + ->unique(fn (Relation $relation) => $relation->uniqueId()) + ->map(fn (Relation $relation) => $this->renderRelation($relation)) ->sort(); } @@ -99,4 +99,4 @@ private function getColumnType(Column $column): string return $type === 'string' ? 'varchar' : $type; } -} \ No newline at end of file +} diff --git a/src/Templates/Er.php b/src/Templates/Er.php index fc455cc..fdca679 100644 --- a/src/Templates/Er.php +++ b/src/Templates/Er.php @@ -32,13 +32,13 @@ class Er implements Template public function render(Collection $tables): string { - $results = $tables->map(fn(Table $table): string => $this->renderTable($table)); - $relations = $tables->flatMap(fn(Table $table) => $table->relations()); + $results = $tables->map(fn (Table $table): string => $this->renderTable($table)); + $relations = $tables->flatMap(fn (Table $table) => $table->relations()); return $results->merge( $relations - ->unique(fn(Relation $relation) => $relation->uniqueId()) - ->map(fn(Relation $relationship) => $this->renderRelations($relationship)) + ->unique(fn (Relation $relation) => $relation->uniqueId()) + ->map(fn (Relation $relationship) => $this->renderRelations($relationship)) ->sort() )->implode("\n"); } @@ -63,7 +63,7 @@ public function save(string $output, string $path, array $options = []): int fclose($fp); $errorOutput = $process->getErrorOutput(); - if (!empty($errorOutput)) { + if (! empty($errorOutput)) { throw new RuntimeException($errorOutput); } @@ -75,8 +75,8 @@ private function renderTable(Table $table): string $primaryKeys = $table->primaryKeys(); $indexes = $table ->relations() - ->filter(fn(Relation $relation) => $relation->type() !== BelongsTo::class) - ->flatMap(fn(Relation $relation) => [ + ->filter(fn (Relation $relation) => $relation->type() !== BelongsTo::class) + ->flatMap(fn (Relation $relation) => [ Helpers::getColumnName($relation->localKey()), Helpers::getColumnName($relation->morphType() ?? ''), ]) @@ -85,16 +85,16 @@ private function renderTable(Table $table): string $result = sprintf("[%s] {}\n", $table->name()); $result .= $table->columns() - ->map(fn(Column $column) => $this->renderColumn($column, $primaryKeys, $indexes)) - ->implode("\n") . "\n"; + ->map(fn (Column $column) => $this->renderColumn($column, $primaryKeys, $indexes)) + ->implode("\n")."\n"; return $result; } /** - * @param Column $column - * @param array $primaryKeys - * @param array $indexes + * @param Column $column + * @param array $primaryKeys + * @param array $indexes * @return string */ private function renderColumn(Column $column, array $primaryKeys, array $indexes): string @@ -118,4 +118,4 @@ private function renderRelations(Relation $relations): string Helpers::getTableName($relations->foreignKey()) ); } -} \ No newline at end of file +} diff --git a/src/Templates/Factory.php b/src/Templates/Factory.php index 0966843..7e6a3cd 100644 --- a/src/Templates/Factory.php +++ b/src/Templates/Factory.php @@ -24,10 +24,10 @@ public function create(string $file): Template private function getExtension(string $file): string { $extension = substr($file, strrpos($file, '.') + 1); - if (!array_key_exists($extension, $this->lookup)) { - throw new RuntimeException('allow [' . implode(',', array_keys($this->lookup)) . '] only'); + if (! array_key_exists($extension, $this->lookup)) { + throw new RuntimeException('allow ['.implode(',', array_keys($this->lookup)).'] only'); } return $extension; } -} \ No newline at end of file +} diff --git a/src/Templates/Template.php b/src/Templates/Template.php index 7f3f99e..73e709d 100644 --- a/src/Templates/Template.php +++ b/src/Templates/Template.php @@ -20,4 +20,4 @@ public function render(Collection $tables): string; * @return int */ public function save(string $output, string $path, array $options = []): int; -} \ No newline at end of file +} diff --git a/tests/Console/Commands/LaravelErdInitCommandTest.php b/tests/Console/Commands/LaravelErdInitCommandTest.php index d2a7653..43b8d51 100644 --- a/tests/Console/Commands/LaravelErdInitCommandTest.php +++ b/tests/Console/Commands/LaravelErdInitCommandTest.php @@ -10,5 +10,4 @@ public function test_download_binary(): void { $this->artisan('laravel-erd:init')->assertSuccessful(); } - -} \ No newline at end of file +} diff --git a/tests/ErdFinderTest.php b/tests/ErdFinderTest.php index 0f4b513..8cc396a 100644 --- a/tests/ErdFinderTest.php +++ b/tests/ErdFinderTest.php @@ -48,7 +48,6 @@ public function test_find_er_model_by_file(): void ); } - /** * @throws Exception */ @@ -75,7 +74,7 @@ public function test_find_er_model_exclude_owner(): void private function givenFinder(): ErdFinder { - return $this->app->make(ErdFinder::class)->in(__DIR__ . '/fixtures'); + return $this->app->make(ErdFinder::class)->in(__DIR__.'/fixtures'); } private function render(Collection $results): string diff --git a/tests/ModelFinderTest.php b/tests/ModelFinderTest.php index 85d58e9..73f1e43 100644 --- a/tests/ModelFinderTest.php +++ b/tests/ModelFinderTest.php @@ -20,7 +20,7 @@ protected function setUp(): void { parent::setUp(); - $this->files = (new ModelFinder)->find(__DIR__ . '/fixtures', '*.php'); + $this->files = (new ModelFinder)->find(__DIR__.'/fixtures', '*.php'); } public function test_it_should_find_user_model(): void @@ -42,4 +42,4 @@ public function test_it_should_not_find_not_eloquent_model(): void { self::assertNotContains(NonModel::class, $this->files); } -} \ No newline at end of file +} diff --git a/tests/RelationFinderTest.php b/tests/RelationFinderTest.php index fce7b2c..ed352aa 100644 --- a/tests/RelationFinderTest.php +++ b/tests/RelationFinderTest.php @@ -39,6 +39,7 @@ class RelationFinderTest extends TestCase BelongsToMany::class => '*--*', MorphToMany::class => '*--*', ]; + private RelationFinder $finder; protected function setUp(): void @@ -62,7 +63,6 @@ public function test_find_mechanic_relations(): void self::assertEquals('cars.mechanic_id', $car->foreignKey()); } - /** * @throws ReflectionException */ @@ -85,7 +85,6 @@ public function test_find_car_relations(): void self::assertEquals('owners.car_id', $owner->foreignKey()); } - /** * @throws ReflectionException */ @@ -101,7 +100,6 @@ public function test_find_owner_relations(): void self::assertEquals('cars.id', $car->foreignKey()); } - /** * @throws ReflectionException */ @@ -124,7 +122,6 @@ public function test_find_post_relations(): void self::assertEquals('users.id', $user->foreignKey()); } - /** * @throws ReflectionException */ @@ -340,4 +337,4 @@ private function renderRelationship(Relation $relation): string Helpers::getTableName($relation->foreignKey()) ); } -} \ No newline at end of file +} diff --git a/tests/Templates/DDLTest.php b/tests/Templates/DDLTest.php index 1e77527..f96a0c9 100644 --- a/tests/Templates/DDLTest.php +++ b/tests/Templates/DDLTest.php @@ -38,7 +38,7 @@ public function test_find_er_model_in_directory(): void private function givenFinder(): ErdFinder { - return $this->app->make(ErdFinder::class)->in(__DIR__ . '/../fixtures'); + return $this->app->make(ErdFinder::class)->in(__DIR__.'/../fixtures'); } private function render(Collection $results): string diff --git a/tests/TestCase.php b/tests/TestCase.php index 0765d74..e28486a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -19,26 +19,26 @@ protected function getPackageProviders($app): array protected function defineEnvironment($app): void { $app['config']->set('laravel-erd.er', [ - 'erd-go' => __DIR__ . '/fixtures/bin/erd-go', - 'dot' => __DIR__ . '/fixtures/bin/dot', + 'erd-go' => __DIR__.'/fixtures/bin/erd-go', + 'dot' => __DIR__.'/fixtures/bin/dot', ]); $app['config']->set('database.default', 'testbench'); $app['config']->set('database.connections.testbench', [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', -// 'driver' => 'mysql', -// 'database' => 'test', -// 'host' => '127.0.0.1', -// 'username' => 'root', -// 'prefix' => '', + // 'driver' => 'mysql', + // 'database' => 'test', + // 'host' => '127.0.0.1', + // 'username' => 'root', + // 'prefix' => '', ]); } protected function defineDatabaseMigrations(): void { $this->loadLaravelMigrations(); - $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); } protected function refreshApplication(): void @@ -46,4 +46,4 @@ protected function refreshApplication(): void parent::refreshApplication(); $this->artisan('laravel-erd:init'); } -} \ No newline at end of file +} diff --git a/tests/fixtures/Models/BaseModel.php b/tests/fixtures/Models/BaseModel.php index cdd04bf..21546cc 100644 --- a/tests/fixtures/Models/BaseModel.php +++ b/tests/fixtures/Models/BaseModel.php @@ -6,5 +6,4 @@ abstract class BaseModel extends Model { - -} \ No newline at end of file +} diff --git a/tests/fixtures/Models/Car.php b/tests/fixtures/Models/Car.php index 555da41..57e9bb7 100644 --- a/tests/fixtures/Models/Car.php +++ b/tests/fixtures/Models/Car.php @@ -17,4 +17,4 @@ public function owner(): HasOne { return $this->HasOne(Owner::class); } -} \ No newline at end of file +} diff --git a/tests/fixtures/Models/Comment.php b/tests/fixtures/Models/Comment.php index 24655cb..0b6918f 100644 --- a/tests/fixtures/Models/Comment.php +++ b/tests/fixtures/Models/Comment.php @@ -14,4 +14,4 @@ public function post(): BelongsTo { return $this->belongsTo(Post::class); } -} \ No newline at end of file +} diff --git a/tests/fixtures/Models/Image.php b/tests/fixtures/Models/Image.php index 95f1625..628ee93 100644 --- a/tests/fixtures/Models/Image.php +++ b/tests/fixtures/Models/Image.php @@ -14,4 +14,4 @@ public function imageable(): MorphTo { return $this->morphTo(); } -} \ No newline at end of file +} diff --git a/tests/fixtures/Models/Mechanic.php b/tests/fixtures/Models/Mechanic.php index b6efb8f..df780fb 100644 --- a/tests/fixtures/Models/Mechanic.php +++ b/tests/fixtures/Models/Mechanic.php @@ -17,6 +17,4 @@ public function carOwner(): HasOneThrough { return $this->hasOneThrough(Owner::class, Car::class); } - } - diff --git a/tests/fixtures/Models/Owner.php b/tests/fixtures/Models/Owner.php index 8d244d9..f534271 100644 --- a/tests/fixtures/Models/Owner.php +++ b/tests/fixtures/Models/Owner.php @@ -11,4 +11,4 @@ public function car(): BelongsTo { return $this->belongsTo(Car::class); } -} \ No newline at end of file +} diff --git a/tests/fixtures/Models/Phone.php b/tests/fixtures/Models/Phone.php index f38b2b2..16e3741 100644 --- a/tests/fixtures/Models/Phone.php +++ b/tests/fixtures/Models/Phone.php @@ -11,4 +11,4 @@ public function user(): BelongsTo { return $this->belongsTo(User::class); } -} \ No newline at end of file +} diff --git a/tests/fixtures/Models/Post.php b/tests/fixtures/Models/Post.php index 57f755b..e432955 100644 --- a/tests/fixtures/Models/Post.php +++ b/tests/fixtures/Models/Post.php @@ -32,4 +32,4 @@ public function image(): MorphOne { return $this->morphOne(Image::class, 'imageable'); } -} \ No newline at end of file +} diff --git a/tests/fixtures/Models/User.php b/tests/fixtures/Models/User.php index c674406..19335d4 100644 --- a/tests/fixtures/Models/User.php +++ b/tests/fixtures/Models/User.php @@ -51,5 +51,4 @@ public function images(): MorphMany { return $this->morphMany(Image::class, 'imageable'); } - -} \ No newline at end of file +} diff --git a/tests/fixtures/NonModel.php b/tests/fixtures/NonModel.php index 3a407a1..8c4fbde 100644 --- a/tests/fixtures/NonModel.php +++ b/tests/fixtures/NonModel.php @@ -4,5 +4,4 @@ class NonModel { - -} \ No newline at end of file +}