From fd32b25c4bb4f5715c00da7263f05dbb48d25c7c Mon Sep 17 00:00:00 2001 From: agis Date: Thu, 17 Sep 2026 15:14:52 +0700 Subject: [PATCH] =?UTF-8?q?refactor(eloquent):=20rename=20SoftDeletingTrai?= =?UTF-8?q?t=E2=86=92SoftDeletes,=20ScopeInterface=E2=86=92Scope,=20Model?= =?UTF-8?q?=20to=20L13=20contracts=20(task=202.5e)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Safe, type-caught slice of task 2.5 (Database). No alias — old FQCNs fatal so the app is forced to conform (task 2.5f, lockstep). - SoftDeletingTrait → SoftDeletes; boot hook bootSoftDeletingTrait() → bootSoftDeletes() (MUST match the new trait basename or Eloquent silently stops registering SoftDeletingScope → soft-deleted rows leak). Proven by DatabaseEloquentBuilderTest:486 (fails when the hook name is wrong). - ScopeInterface → Scope; SoftDeletingScope + Model typehints updated. - Model implements Illuminate\Contracts\Support\{Arrayable,Jsonable} (were Illuminate\Support\Contracts\{ArrayableInterface,JsonableInterface}); the 2 Model instanceof checks migrated to Arrayable. BC-safe: old contracts extend the new ones, so instanceof Arrayable is strictly wider. Does NOT touch lists()/pluck() — that dangerous semantic swap is the separate 2.5a–d pipeline. Fork suites green (Database 513, Support/Http/View 199). Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Illuminate/Database/Eloquent/Model.php | 26 +++++++++---------- .../{ScopeInterface.php => Scope.php} | 2 +- ...{SoftDeletingTrait.php => SoftDeletes.php} | 4 +-- .../Database/Eloquent/SoftDeletingScope.php | 2 +- .../Database/DatabaseEloquentBuilderTest.php | 4 +-- .../DatabaseSoftDeletingTraitTest.php | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) rename src/Illuminate/Database/Eloquent/{ScopeInterface.php => Scope.php} (94%) rename src/Illuminate/Database/Eloquent/{SoftDeletingTrait.php => SoftDeletes.php} (97%) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 9f0cd7015..f0cf26986 100755 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -15,8 +15,8 @@ use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphTo; -use Illuminate\Support\Contracts\JsonableInterface; -use Illuminate\Support\Contracts\ArrayableInterface; +use Illuminate\Contracts\Support\Jsonable; +use Illuminate\Contracts\Support\Arrayable; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphMany; @@ -27,7 +27,7 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\ConnectionResolverInterface as Resolver; -abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterface, JsonSerializable { +abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable { /** * The connection name for the model. @@ -265,11 +265,11 @@ protected static function bootTraits(): void /** * Register a new global scope on the model. * - * @param ScopeInterface $scope + * @param Scope $scope * * @return void */ - public static function addGlobalScope(ScopeInterface $scope): void + public static function addGlobalScope(Scope $scope): void { static::$globalScopes[get_called_class()][get_class($scope)] = $scope; } @@ -277,7 +277,7 @@ public static function addGlobalScope(ScopeInterface $scope): void /** * Determine if a model has a global scope. * - * @param ScopeInterface $scope + * @param Scope $scope * * @return bool */ @@ -289,11 +289,11 @@ public static function hasGlobalScope($scope): bool /** * Get a global scope registered with the model. * - * @param ScopeInterface $scope + * @param Scope $scope * - * @return ScopeInterface|null + * @return Scope|null */ - public static function getGlobalScope($scope): ?ScopeInterface + public static function getGlobalScope($scope): ?Scope { return Arr::first(static::$globalScopes[get_called_class()], function($value, $key) use ($scope) { @@ -304,7 +304,7 @@ public static function getGlobalScope($scope): ?ScopeInterface /** * Get the global scopes for this class instance. * - * @return ScopeInterface[] + * @return Scope[] */ public function getGlobalScopes(): array { @@ -1740,7 +1740,7 @@ public function newQuery() /** * Get a new query instance without a given scope. * - * @param ScopeInterface $scope + * @param Scope $scope * * @return Builder */ @@ -2317,7 +2317,7 @@ public function relationsToArray():array // If the values implements the Arrayable interface we can just call this // toArray method on the instances which will convert both models and // collections to their proper array form and we'll set the values. - if ($value instanceof ArrayableInterface) + if ($value instanceof Arrayable) { $relation = $value->toArray(); } @@ -2515,7 +2515,7 @@ protected function mutateAttributeForArray($key, $value) { $value = $this->mutateAttribute($key, $value); - return $value instanceof ArrayableInterface ? $value->toArray() : $value; + return $value instanceof Arrayable ? $value->toArray() : $value; } /** diff --git a/src/Illuminate/Database/Eloquent/ScopeInterface.php b/src/Illuminate/Database/Eloquent/Scope.php similarity index 94% rename from src/Illuminate/Database/Eloquent/ScopeInterface.php rename to src/Illuminate/Database/Eloquent/Scope.php index b0a93a90c..da1173af1 100644 --- a/src/Illuminate/Database/Eloquent/ScopeInterface.php +++ b/src/Illuminate/Database/Eloquent/Scope.php @@ -1,6 +1,6 @@