From 36ff96c6c91c3d94711a4c0904131a4f2e3d1d99 Mon Sep 17 00:00:00 2001 From: Bastien Philippe Date: Fri, 24 Nov 2023 11:00:28 +0100 Subject: [PATCH] fix phpstan analysis --- phpstan-baseline.neon | 10 ---------- src/Mixins/CollectionMixin.php | 9 +++++---- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a1183a1..fca43a2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,15 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Cannot call method getKeyName\\(\\) on Illuminate\\\\Database\\\\Eloquent\\\\Model\\|null\\.$#" - count: 2 - path: src/Mixins/CollectionMixin.php - - - - message: "#^Cannot call method newModelQuery\\(\\) on Illuminate\\\\Database\\\\Eloquent\\\\Model\\|null\\.$#" - count: 1 - path: src/Mixins/CollectionMixin.php - - message: "#^PHPDoc tag @mixin contains generic class Illuminate\\\\Database\\\\Eloquent\\\\Collection but does not specify its types\\: TKey, TModel$#" count: 1 diff --git a/src/Mixins/CollectionMixin.php b/src/Mixins/CollectionMixin.php index ad39b0d..84c39ba 100644 --- a/src/Mixins/CollectionMixin.php +++ b/src/Mixins/CollectionMixin.php @@ -13,15 +13,16 @@ class CollectionMixin public function loadAttributes(): Closure { return function (Closure $closure): self { - if ($this->isEmpty()) { + $model = $this->first(); + if ($model === null) { return $this; } - $query = $this->first()->newModelQuery() + $query = $model->newModelQuery() ->whereKey($this->modelKeys()) - ->select($this->first()->getKeyName()); + ->select($model->getKeyName()); $query = $closure($query) ?? $query; - $models = $query->get()->keyBy($this->first()->getKeyName()); + $models = $query->get()->keyBy($model->getKeyName()); $attributes = Arr::except( array_keys($models->first()->getAttributes()),