diff --git a/phpstan.neon b/phpstan.neon index baaf120dc..cc8ea2eb8 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -41,3 +41,5 @@ parameters: - '#Method Hyperf\\Utils\\Serializer\\ScalarNormalizer::denormalize\(\) should return array\|object but returns#' - '#Function get_debug_type invoked with 1 parameter, 0 required#' - '#gc_status not found#' + - '#Call to an undefined method Hyperf\\Utils\\HigherOrderCollectionProxy::toMessage().#' + - '#Access to an undefined property Hyperf\\Resource\\Json\\JsonResource::\$preserveKeys.#' diff --git a/src/resource/src/Concerns/ConditionallyLoadsAttributes.php b/src/resource/src/Concerns/ConditionallyLoadsAttributes.php index 22f93a225..c61f6dcab 100644 --- a/src/resource/src/Concerns/ConditionallyLoadsAttributes.php +++ b/src/resource/src/Concerns/ConditionallyLoadsAttributes.php @@ -97,7 +97,7 @@ trait ConditionallyLoadsAttributes if (($value instanceof PotentiallyMissing && $value->isMissing()) || ($value instanceof self && $value->resource instanceof PotentiallyMissing && - $value->isMissing())) { + $value->resource->isMissing())) { unset($data[$key]); } else { $numericKeys = $numericKeys && is_numeric($key); diff --git a/src/resource/src/Json/ResourceCollection.php b/src/resource/src/Json/ResourceCollection.php index 10235477f..c11d15c25 100644 --- a/src/resource/src/Json/ResourceCollection.php +++ b/src/resource/src/Json/ResourceCollection.php @@ -9,6 +9,7 @@ declare(strict_types=1); * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Resource\Json; use Countable; @@ -62,7 +63,9 @@ class ResourceCollection extends JsonResource implements Countable, IteratorAggr */ public function toArray(): array { - return $this->collection->map->toArray()->all(); + /** @var Collection $collection */ + $collection = $this->collection->map->toArray(); + return $collection->all(); } public function toResponse() @@ -76,6 +79,9 @@ class ResourceCollection extends JsonResource implements Countable, IteratorAggr public function toMessage() { - return $this->collection->map->toMessage()->all(); + /** @var Collection $collection */ + $collection = $this->collection->map->toMessage(); + + return $collection->all(); } }