From 1a7f963536374657caa4532f4d5fc87ec389410f Mon Sep 17 00:00:00 2001 From: Ryan Chandler Date: Tue, 3 Oct 2023 00:02:59 +0100 Subject: [PATCH] wip --- src/Actions/DeleteSourceFile.php | 8 ++++---- src/Actions/InitialiseOrbitalTable.php | 4 ++-- src/Actions/MaybeCreateOrbitDirectories.php | 4 ++-- src/Actions/SaveCompiledAttributesToFile.php | 6 +++--- src/Concerns/Orbital.php | 10 +++++----- src/Concerns/SoftDeletes.php | 10 +++++----- src/OrbitServiceProvider.php | 1 - src/Support/ModelAttributeFormatter.php | 2 +- src/Support/ModelUsesSoftDeletes.php | 4 ++-- tests/Feature/Orbital/SoftDeleteTest.php | 2 +- tests/Pest.php | 1 - 11 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/Actions/DeleteSourceFile.php b/src/Actions/DeleteSourceFile.php index 4f77647..28a55d0 100644 --- a/src/Actions/DeleteSourceFile.php +++ b/src/Actions/DeleteSourceFile.php @@ -9,15 +9,15 @@ class DeleteSourceFile { - public function execute(Orbit & Model $model, Driver $driver): void + public function execute(Orbit&Model $model, Driver $driver): void { - $directory = config('orbit.paths.content') . DIRECTORY_SEPARATOR . $model->getOrbitSource(); + $directory = config('orbit.paths.content').DIRECTORY_SEPARATOR.$model->getOrbitSource(); $filename = "{$model->getKey()}.{$driver->extension()}"; $fs = new Filesystem(); - if ($fs->exists($directory . DIRECTORY_SEPARATOR . $filename)) { - $fs->delete($directory . DIRECTORY_SEPARATOR . $filename); + if ($fs->exists($directory.DIRECTORY_SEPARATOR.$filename)) { + $fs->delete($directory.DIRECTORY_SEPARATOR.$filename); } } } diff --git a/src/Actions/InitialiseOrbitalTable.php b/src/Actions/InitialiseOrbitalTable.php index b8ead9c..dcb4349 100644 --- a/src/Actions/InitialiseOrbitalTable.php +++ b/src/Actions/InitialiseOrbitalTable.php @@ -9,14 +9,14 @@ class InitialiseOrbitalTable { - public function hasTable(Orbit & Model $model): bool + public function hasTable(Orbit&Model $model): bool { $schemaBuilder = $model->resolveConnection()->getSchemaBuilder(); return $schemaBuilder->hasTable($model->getTable()); } - public function migrate(Orbit & Model $model): void + public function migrate(Orbit&Model $model): void { $table = $model->getTable(); $schemaBuilder = $model->resolveConnection()->getSchemaBuilder(); diff --git a/src/Actions/MaybeCreateOrbitDirectories.php b/src/Actions/MaybeCreateOrbitDirectories.php index bfa1e8f..cc9d000 100644 --- a/src/Actions/MaybeCreateOrbitDirectories.php +++ b/src/Actions/MaybeCreateOrbitDirectories.php @@ -8,7 +8,7 @@ class MaybeCreateOrbitDirectories { - public function execute((Orbit & Model)|null $model = null) + public function execute(Orbit&Model $model = null) { $fs = new Filesystem(); @@ -20,7 +20,7 @@ public function execute((Orbit & Model)|null $model = null) } if ($model !== null) { - $modelDirectory = config('orbit.paths.content') . DIRECTORY_SEPARATOR . $model->getOrbitSource(); + $modelDirectory = config('orbit.paths.content').DIRECTORY_SEPARATOR.$model->getOrbitSource(); $fs->ensureDirectoryExists($modelDirectory); } diff --git a/src/Actions/SaveCompiledAttributesToFile.php b/src/Actions/SaveCompiledAttributesToFile.php index 2a14919..8061ddf 100644 --- a/src/Actions/SaveCompiledAttributesToFile.php +++ b/src/Actions/SaveCompiledAttributesToFile.php @@ -9,12 +9,12 @@ class SaveCompiledAttributesToFile { - public function execute(Orbit & Model $model, string $compiledAttributes, Driver $driver): void + public function execute(Orbit&Model $model, string $compiledAttributes, Driver $driver): void { - $directory = config('orbit.paths.content') . DIRECTORY_SEPARATOR . $model->getOrbitSource(); + $directory = config('orbit.paths.content').DIRECTORY_SEPARATOR.$model->getOrbitSource(); $filename = "{$model->getKey()}.{$driver->extension()}"; $fs = new Filesystem(); - $fs->put($directory . DIRECTORY_SEPARATOR . $filename, $compiledAttributes); + $fs->put($directory.DIRECTORY_SEPARATOR.$filename, $compiledAttributes); } } diff --git a/src/Concerns/Orbital.php b/src/Concerns/Orbital.php index ab81230..3d665bd 100644 --- a/src/Concerns/Orbital.php +++ b/src/Concerns/Orbital.php @@ -28,13 +28,13 @@ public static function bootOrbital() $driver = $model->getOrbitDriver(); - if (!class_exists($driver)) { + if (! class_exists($driver)) { throw InvalidDriverException::make($driver); } $driver = app($driver); - if (!$driver instanceof Driver) { + if (! $driver instanceof Driver) { throw InvalidDriverException::make($driver::class); } @@ -46,7 +46,7 @@ public static function bootOrbital() $saveCompiledAttributesToFile = new SaveCompiledAttributesToFile(); - static::created(function (Orbit & Model $model) use ($driver, $saveCompiledAttributesToFile) { + static::created(function (Orbit&Model $model) use ($driver, $saveCompiledAttributesToFile) { $model->refresh(); $attributes = ModelAttributeFormatter::format($model, $model->getAttributes()); @@ -55,7 +55,7 @@ public static function bootOrbital() $saveCompiledAttributesToFile->execute($model, $compiledAttributes, $driver); }); - static::updated(function (Orbit & Model $model) use ($driver, $saveCompiledAttributesToFile) { + static::updated(function (Orbit&Model $model) use ($driver, $saveCompiledAttributesToFile) { $model->refresh(); $attributes = ModelAttributeFormatter::format($model, $model->getAttributes()); @@ -64,7 +64,7 @@ public static function bootOrbital() $saveCompiledAttributesToFile->execute($model, $compiledAttributes, $driver); }); - static::deleted(function (Orbit & Model $model) use ($driver) { + static::deleted(function (Orbit&Model $model) use ($driver) { if (ModelUsesSoftDeletes::check($model)) { return; } diff --git a/src/Concerns/SoftDeletes.php b/src/Concerns/SoftDeletes.php index a09ad30..0fd2bc5 100644 --- a/src/Concerns/SoftDeletes.php +++ b/src/Concerns/SoftDeletes.php @@ -27,19 +27,19 @@ public static function bootSoftDeletes() $model = new static(); $driver = $model->getOrbitDriver(); - if (!class_exists($driver)) { + if (! class_exists($driver)) { throw InvalidDriverException::make($driver); } $driver = app($driver); - if (!$driver instanceof Driver) { + if (! $driver instanceof Driver) { throw InvalidDriverException::make($driver::class); } $saveCompiledAttributesToFile = new SaveCompiledAttributesToFile(); - static::deleted(function (Orbit & Model $model) use ($driver, $saveCompiledAttributesToFile) { + static::deleted(function (Orbit&Model $model) use ($driver, $saveCompiledAttributesToFile) { $model->refresh(); $attributes = ModelAttributeFormatter::format($model, $model->getAttributes()); @@ -48,7 +48,7 @@ public static function bootSoftDeletes() $saveCompiledAttributesToFile->execute($model, $compiledAttributes, $driver); }); - static::restored(function (Orbit & Model $model) use ($driver, $saveCompiledAttributesToFile) { + static::restored(function (Orbit&Model $model) use ($driver, $saveCompiledAttributesToFile) { $model->refresh(); $attributes = ModelAttributeFormatter::format($model, $model->getAttributes()); @@ -57,7 +57,7 @@ public static function bootSoftDeletes() $saveCompiledAttributesToFile->execute($model, $compiledAttributes, $driver); }); - static::forceDeleted(function (Orbit & Model $model) use ($driver) { + static::forceDeleted(function (Orbit&Model $model) use ($driver) { $deleteSourceFile = new DeleteSourceFile(); $deleteSourceFile->execute($model, $driver); }); diff --git a/src/OrbitServiceProvider.php b/src/OrbitServiceProvider.php index b9d027b..909d84d 100644 --- a/src/OrbitServiceProvider.php +++ b/src/OrbitServiceProvider.php @@ -3,7 +3,6 @@ namespace Orbit; use Illuminate\Config\Repository; -use Illuminate\Filesystem\Filesystem; use Orbit\Actions\MaybeCreateOrbitDirectories; use Spatie\LaravelPackageTools\Commands\InstallCommand; use Spatie\LaravelPackageTools\Package; diff --git a/src/Support/ModelAttributeFormatter.php b/src/Support/ModelAttributeFormatter.php index 39975a8..c696a70 100644 --- a/src/Support/ModelAttributeFormatter.php +++ b/src/Support/ModelAttributeFormatter.php @@ -8,7 +8,7 @@ class ModelAttributeFormatter { - public static function format(Orbit & Model $model, array $attributes): array + public static function format(Orbit&Model $model, array $attributes): array { $formatted = []; diff --git a/src/Support/ModelUsesSoftDeletes.php b/src/Support/ModelUsesSoftDeletes.php index 39d5a81..8715397 100644 --- a/src/Support/ModelUsesSoftDeletes.php +++ b/src/Support/ModelUsesSoftDeletes.php @@ -3,12 +3,12 @@ namespace Orbit\Support; use Illuminate\Database\Eloquent\Model; -use Orbit\Contracts\Orbit; use Orbit\Concerns\SoftDeletes; +use Orbit\Contracts\Orbit; class ModelUsesSoftDeletes { - public static function check(Orbit & Model $model): bool + public static function check(Orbit&Model $model): bool { $uses = class_uses_recursive($model); diff --git a/tests/Feature/Orbital/SoftDeleteTest.php b/tests/Feature/Orbital/SoftDeleteTest.php index 17fc585..64a1ecb 100644 --- a/tests/Feature/Orbital/SoftDeleteTest.php +++ b/tests/Feature/Orbital/SoftDeleteTest.php @@ -42,7 +42,7 @@ expect(base_path("content/categories/{$category->id}.md")) ->toBeFile() ->and(file_get_contents(base_path("content/categories/{$category->id}.md"))) - ->toContain(<<toContain(<<<'MD' deleted_at: null MD); }); diff --git a/tests/Pest.php b/tests/Pest.php index 14d24b3..a7b28ca 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,4 +1,3 @@ in('Feature');