From 31ebfc86e5c707954b88c43fbe872cb06bc76d28 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 24 Jun 2021 09:56:39 -0500 Subject: [PATCH] formatting --- .../Pagination/AbstractCursorPaginator.php | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Illuminate/Pagination/AbstractCursorPaginator.php b/src/Illuminate/Pagination/AbstractCursorPaginator.php index 40995ecbee7b..72698705205e 100644 --- a/src/Illuminate/Pagination/AbstractCursorPaginator.php +++ b/src/Illuminate/Pagination/AbstractCursorPaginator.php @@ -196,9 +196,13 @@ public function getParametersForItem($item) ->flip() ->map(function ($_, $parameterName) use ($item) { if ($item instanceof ArrayAccess || is_array($item)) { - return $this->castParameter($item[$parameterName] ?? $item[Str::afterLast($parameterName, '.')]); + return $this->ensureParameterIsPrimitive( + $item[$parameterName] ?? $item[Str::afterLast($parameterName, '.')] + ); } elseif (is_object($item)) { - return $this->castParameter($item->{$parameterName} ?? $item->{Str::afterLast($parameterName, '.')}); + return $this->ensureParameterIsPrimitive( + $item->{$parameterName} ?? $item->{Str::afterLast($parameterName, '.')} + ); } throw new Exception('Only arrays and objects are supported when cursor paginating items.'); @@ -206,20 +210,18 @@ public function getParametersForItem($item) } /** - * Casts the given item parameter. When the given parameter is an object and can - * be cast to a string, the stringified representation will be returned, - * otherwise the original parameter will be returned. + * Ensure the parameter is a primitive type. + * + * This can resolve issues that arise the developer uses a value object for an attribute. * * @param mixed $parameter - * @return string + * @return mixed */ - public function castParameter($parameter) + protected function ensureParameterIsPrimitive($parameter) { - if (is_object($parameter) && method_exists($parameter, '__toString')) { - return (string) $parameter; - } - - return $parameter; + return is_object($parameter) && method_exists($parameter, '__toString') + ? (string) $parameter + : $parameter; } /**