Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangjchandler committed Oct 2, 2023
1 parent 70231b4 commit 1a7f963
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/Actions/DeleteSourceFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
4 changes: 2 additions & 2 deletions src/Actions/InitialiseOrbitalTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/Actions/MaybeCreateOrbitDirectories.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class MaybeCreateOrbitDirectories
{
public function execute((Orbit & Model)|null $model = null)
public function execute(Orbit&Model $model = null)
{
$fs = new Filesystem();

Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Actions/SaveCompiledAttributesToFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 5 additions & 5 deletions src/Concerns/Orbital.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Concerns/SoftDeletes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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);
});
Expand Down
1 change: 0 additions & 1 deletion src/OrbitServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Support/ModelAttributeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down
4 changes: 2 additions & 2 deletions src/Support/ModelUsesSoftDeletes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Orbital/SoftDeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(<<<MD
->toContain(<<<'MD'
deleted_at: null
MD);
});
Expand Down
1 change: 0 additions & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?php


uses(Tests\TestCase::class)->in('Feature');

0 comments on commit 1a7f963

Please sign in to comment.