From 2d00d4f960a59191b4765064fe0395eb26cdc6d0 Mon Sep 17 00:00:00 2001 From: kingIZZZY <1576535+kingIZZZY@users.noreply.github.com> Date: Tue, 25 Nov 2025 21:59:29 -0500 Subject: [PATCH 1/6] Optimized the parameters of method `__call()` to make them more standardized. (#7637) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 李铭昕 <715557344@qq.com> --- src/Model/Builder.php | 39 +++++++++++++++----------------- src/Model/Model.php | 13 ++++------- src/Model/Relations/MorphTo.php | 13 ++++------- src/Model/Relations/Relation.php | 11 ++++----- src/Query/Builder.php | 15 ++++++------ src/Schema/Schema.php | 2 +- 6 files changed, 40 insertions(+), 53 deletions(-) diff --git a/src/Model/Builder.php b/src/Model/Builder.php index 55332ff..b9cded3 100755 --- a/src/Model/Builder.php +++ b/src/Model/Builder.php @@ -124,45 +124,42 @@ public function __construct(QueryBuilder $query) /** * Dynamically handle calls into the query instance. - * - * @param string $method - * @param array $parameters */ - public function __call($method, $parameters) + public function __call(string $name, array $arguments): mixed { - if ($method === 'macro') { - $this->localMacros[$parameters[0]] = $parameters[1]; + if ($name === 'macro') { + $this->localMacros[$arguments[0]] = $arguments[1]; - return; + return null; } - if ($method === 'mixin') { - return static::registerMixin($parameters[0], $parameters[1] ?? true); + if ($name === 'mixin') { + return static::registerMixin($arguments[0], $arguments[1] ?? true); } - if ($this->hasMacro($method)) { - array_unshift($parameters, $this); + if ($this->hasMacro($name)) { + array_unshift($arguments, $this); - return $this->localMacros[$method](...$parameters); + return $this->localMacros[$name](...$arguments); } - if (static::hasGlobalMacro($method)) { - if (static::$macros[$method] instanceof Closure) { - return call_user_func_array(static::$macros[$method]->bindTo($this, static::class), $parameters); + if (static::hasGlobalMacro($name)) { + if (static::$macros[$name] instanceof Closure) { + return call_user_func_array(static::$macros[$name]->bindTo($this, static::class), $arguments); } - return call_user_func_array(static::$macros[$method], $parameters); + return call_user_func_array(static::$macros[$name], $arguments); } - if (isset($this->model) && method_exists($this->model, $scope = 'scope' . ucfirst($method))) { - return $this->callScope([$this->model, $scope], $parameters); + if (isset($this->model) && method_exists($this->model, $scope = 'scope' . ucfirst($name))) { + return $this->callScope([$this->model, $scope], $arguments); } - if (in_array($method, $this->passthru)) { - return $this->toBase()->{$method}(...$parameters); + if (in_array($name, $this->passthru)) { + return $this->toBase()->{$name}(...$arguments); } - $this->query->{$method}(...$parameters); + $this->query->{$name}(...$arguments); return $this; } diff --git a/src/Model/Model.php b/src/Model/Model.php index cbdf9d8..682b5e8 100644 --- a/src/Model/Model.php +++ b/src/Model/Model.php @@ -179,21 +179,18 @@ public function __unset($key) /** * Handle dynamic method calls into the model. - * - * @param string $method - * @param array $parameters */ - public function __call($method, $parameters) + public function __call(string $name, array $arguments): mixed { - if (in_array($method, ['increment', 'decrement'])) { - return $this->{$method}(...$parameters); + if (in_array($name, ['increment', 'decrement'])) { + return $this->{$name}(...$arguments); } - if ($resolver = $this->relationResolver(static::class, $method)) { + if ($resolver = $this->relationResolver(static::class, $name)) { return $resolver($this); } - return $this->newQuery()->{$method}(...$parameters); + return $this->newQuery()->{$name}(...$arguments); } /** diff --git a/src/Model/Relations/MorphTo.php b/src/Model/Relations/MorphTo.php index 0269453..5a5788d 100644 --- a/src/Model/Relations/MorphTo.php +++ b/src/Model/Relations/MorphTo.php @@ -80,17 +80,14 @@ public function __construct(Builder $query, Model $parent, $foreignKey, $ownerKe /** * Handle dynamic method calls to the relationship. - * - * @param string $method - * @param array $parameters */ - public function __call($method, $parameters) + public function __call(string $name, array $arguments): mixed { try { - $result = parent::__call($method, $parameters); + $result = parent::__call($name, $arguments); - if (in_array($method, ['select', 'selectRaw', 'selectSub', 'addSelect', 'withoutGlobalScopes'])) { - $this->macroBuffer[] = compact('method', 'parameters'); + if (in_array($name, ['select', 'selectRaw', 'selectSub', 'addSelect', 'withoutGlobalScopes'])) { + $this->macroBuffer[] = compact('name', 'arguments'); } return $result; @@ -100,7 +97,7 @@ public function __call($method, $parameters) // we'll assume that we want to call a query macro (e.g. withTrashed) that only // exists on related models. We will just store the call and replay it later. catch (BadMethodCallException $e) { - $this->macroBuffer[] = compact('method', 'parameters'); + $this->macroBuffer[] = compact('name', 'arguments'); return $this; } diff --git a/src/Model/Relations/Relation.php b/src/Model/Relations/Relation.php index 03fd328..15eee06 100755 --- a/src/Model/Relations/Relation.php +++ b/src/Model/Relations/Relation.php @@ -84,17 +84,14 @@ public function __construct(Builder $query, Model $parent) /** * Handle dynamic method calls to the relationship. - * - * @param string $method - * @param array $parameters */ - public function __call($method, $parameters) + public function __call(string $name, array $arguments): mixed { - if (static::hasMacro($method)) { - return $this->macroCall($method, $parameters); + if (static::hasMacro($name)) { + return $this->macroCall($name, $arguments); } - $result = $this->forwardCallTo($this->query, $method, $parameters); + $result = $this->forwardCallTo($this->query, $name, $arguments); if ($result === $this->query) { return $this; diff --git a/src/Query/Builder.php b/src/Query/Builder.php index ecfbf97..18e4db3 100755 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -267,20 +267,19 @@ public function __construct( /** * Handle dynamic method calls into the method. * - * @param string $method - * @param array $parameters * @throws BadMethodCallException */ - public function __call($method, $parameters) + public function __call(string $name, array $arguments): mixed { - if (static::hasMacro($method)) { - return $this->macroCall($method, $parameters); + if (static::hasMacro($name)) { + return $this->macroCall($name, $arguments); } - if (Str::startsWith($method, 'where')) { - return $this->dynamicWhere($method, $parameters); + if (Str::startsWith($name, 'where')) { + return $this->dynamicWhere($name, $arguments); } - static::throwBadMethodCallException($method); + static::throwBadMethodCallException($name); + return null; } /** diff --git a/src/Schema/Schema.php b/src/Schema/Schema.php index 55cded1..b7b3c3a 100644 --- a/src/Schema/Schema.php +++ b/src/Schema/Schema.php @@ -59,7 +59,7 @@ public static function __callStatic($name, $arguments) return $connection->getSchemaBuilder()->{$name}(...$arguments); } - public function __call($name, $arguments) + public function __call(string $name, array $arguments): mixed { return self::__callStatic($name, $arguments); } From d54974856b70f3e05a83f4530ce06dad51e0ccb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=93=AD=E6=98=95?= <715557344@qq.com> Date: Mon, 1 Dec 2025 11:37:59 +0800 Subject: [PATCH 2/6] Fixed test cases (#7643) --- src/Model/Model.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Model/Model.php b/src/Model/Model.php index 1034632..742b9e0 100644 --- a/src/Model/Model.php +++ b/src/Model/Model.php @@ -29,6 +29,7 @@ use JsonSerializable; use Psr\EventDispatcher\EventDispatcherInterface; use Psr\EventDispatcher\StoppableEventInterface; +use Stringable; use Throwable; use function Hyperf\Collection\collect; @@ -40,7 +41,7 @@ /** * @mixin ModelIDE */ -abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable, CompressInterface +abstract class Model implements Stringable, ArrayAccess, Arrayable, Jsonable, JsonSerializable, CompressInterface { use Concerns\HasAttributes; use Concerns\HasEvents; From b1edc7af2c209483850c2d920627e18136c5bb65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=93=AD=E6=98=95?= <715557344@qq.com> Date: Mon, 1 Dec 2025 18:06:18 +0800 Subject: [PATCH 3/6] Optimized phpdoc for `Closure():TReturn`. (#7650) --- src/Model/Relations/Relation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Relations/Relation.php b/src/Model/Relations/Relation.php index 03fd328..08107dd 100755 --- a/src/Model/Relations/Relation.php +++ b/src/Model/Relations/Relation.php @@ -115,7 +115,7 @@ public function __clone() * Run a callback with constraints disabled on the relation. * * @template TCallbackReturn - * @param Closure(): TCallbackReturn $callback + * @param (Closure(): TCallbackReturn) $callback * @return TCallbackReturn */ public static function noConstraints(Closure $callback) From 9e6a92e258041c0ff50434c4d0eb53e51ac33e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=93=AD=E6=98=95?= <715557344@qq.com> Date: Tue, 2 Dec 2025 15:31:02 +0800 Subject: [PATCH 4/6] format code (#7654) --- src/Model/Model.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Model/Model.php b/src/Model/Model.php index 682b5e8..d3bb9cf 100644 --- a/src/Model/Model.php +++ b/src/Model/Model.php @@ -29,6 +29,7 @@ use JsonSerializable; use Psr\EventDispatcher\EventDispatcherInterface; use Psr\EventDispatcher\StoppableEventInterface; +use Stringable; use Throwable; use function Hyperf\Collection\collect; @@ -40,7 +41,7 @@ /** * @mixin ModelIDE */ -abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable, CompressInterface +abstract class Model implements Stringable, ArrayAccess, Arrayable, Jsonable, JsonSerializable, CompressInterface { use Concerns\HasAttributes; use Concerns\HasEvents; From 223df68ac99e95076f3dab174cd0c32c4769be6b Mon Sep 17 00:00:00 2001 From: "Mr.tang" Date: Tue, 2 Dec 2025 22:30:56 +0800 Subject: [PATCH 5/6] phpstrom Code prompt optimization (#7579) --- src/Model/Relations/Relation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Relations/Relation.php b/src/Model/Relations/Relation.php index 08107dd..16ff7a8 100755 --- a/src/Model/Relations/Relation.php +++ b/src/Model/Relations/Relation.php @@ -115,7 +115,7 @@ public function __clone() * Run a callback with constraints disabled on the relation. * * @template TCallbackReturn - * @param (Closure(): TCallbackReturn) $callback + * @param Closure():TCallbackReturn $callback * @return TCallbackReturn */ public static function noConstraints(Closure $callback) From dc6cfae2edcee277a6eecffcdfa83014593f8899 Mon Sep 17 00:00:00 2001 From: Deeka Wong Date: Thu, 4 Dec 2025 11:05:16 +0800 Subject: [PATCH 6/6] feat: update HasUuids to use UUIDv7 instead of ordered UUID (#7644) --- src/Model/Concerns/HasUuids.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Concerns/HasUuids.php b/src/Model/Concerns/HasUuids.php index 3bd3603..5d27dbe 100644 --- a/src/Model/Concerns/HasUuids.php +++ b/src/Model/Concerns/HasUuids.php @@ -23,7 +23,7 @@ trait HasUuids */ public function newUniqueId() { - return (string) Str::orderedUuid(); + return (string) Str::uuidv7(); } /**