Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze authored and github-actions[bot] committed Apr 24, 2024
1 parent 410093d commit ba1891f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/HasStatuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
use Spatie\ModelStatus\Events\StatusUpdated;
use Spatie\ModelStatus\Exceptions\InvalidEnumClass;
use Spatie\ModelStatus\Exceptions\InvalidEnumType;
use Spatie\ModelStatus\Exceptions\InvalidStatus;
use Spatie\ModelStatus\Exceptions\InvalidEnumClass;

trait HasStatuses
{

public abstract static function getStatusEnumClass(): string;
abstract public static function getStatusEnumClass(): string;

public function statuses(): MorphMany
{
if (!self::enumIsStringBacked())
if (! self::enumIsStringBacked()) {
throw InvalidEnumType::create(self::getStatusEnumClass());
}

return $this->morphMany($this->getStatusModelClassName(), 'model', 'model_type', $this->getModelKeyColumnName())
->latest('id');
Expand All @@ -34,7 +35,7 @@ public function status(): ?Status

public function setStatus($statusEnum, ?string $reason = null): self
{
if (!$this->isValidStatus($statusEnum, $reason)) {
if (! $this->isValidStatus($statusEnum, $reason)) {
throw InvalidStatus::create($statusEnum->value);
}

Expand Down Expand Up @@ -148,6 +149,7 @@ function (QueryBuilder $query) use ($statusEnums) {
private static function isInstanceOfEnum($statusEnum): bool
{
$statusEnumType = self::getStatusEnumClass();

return $statusEnum instanceof $statusEnumType;
}

Expand All @@ -159,8 +161,9 @@ private static function enumIsStringBacked(): bool

public function forceSetStatus($statusEnum, ?string $reason = null): self
{
if (!self::isInstanceOfEnum($statusEnum))
if (! self::isInstanceOfEnum($statusEnum)) {
throw InvalidEnumClass::create(self::getStatusEnumClass());
}

$oldStatus = $this->latestStatus();

Expand Down
5 changes: 3 additions & 2 deletions tests/HasStatusesTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use Illuminate\Database\Eloquent\Relations\Relation;
use Spatie\ModelStatus\Exceptions\InvalidEnumClass;
use Spatie\ModelStatus\Exceptions\InvalidEnumType;
use Spatie\ModelStatus\Exceptions\InvalidStatus;
use Spatie\ModelStatus\Exceptions\InvalidEnumClass;
use Spatie\ModelStatus\Tests\Models\AlternativeStatusModel;
use Spatie\ModelStatus\Tests\Models\CustomModelKeyStatusModel;
use Spatie\ModelStatus\Tests\Models\TestEnum;
Expand Down Expand Up @@ -56,7 +56,8 @@

it('throws an exception if status enum instance was from a different enum', function () {
$this->testModel->setStatus(TestEnum2::TestStatus, 'test');
})->throws(InvalidEnumClass::class);;
})->throws(InvalidEnumClass::class);
;


it('can find the last status by enum', function () {
Expand Down

0 comments on commit ba1891f

Please sign in to comment.