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/Concerns/HasUuids.php b/src/Model/Concerns/HasUuids.php index 506a995..6a8215f 100644 --- a/src/Model/Concerns/HasUuids.php +++ b/src/Model/Concerns/HasUuids.php @@ -25,7 +25,7 @@ trait HasUuids */ public function newUniqueId() { - return (string) Str::orderedUuid(); + return (string) Str::uuidv7(); } /** diff --git a/src/Model/Model.php b/src/Model/Model.php index cbdf9d8..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; @@ -179,21 +180,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..5fac89d 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; @@ -115,7 +112,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) 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); }