From 112d8c0ddc525411d5a16c94b129ba0366b20cdc Mon Sep 17 00:00:00 2001 From: ilestis Date: Thu, 8 Aug 2024 12:33:54 -0600 Subject: [PATCH] PHpstan --- app/Models/Location.php | 1 + .../Entity/Connections/MapService.php | 20 +++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/Models/Location.php b/app/Models/Location.php index 535fc8a79..f4fdb6927 100644 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -29,6 +29,7 @@ * @property bool|int $is_map_private * @property ?int $location_id * @property Map[]|Collection $maps + * @property ?Location $parent * @property Location[]|Collection $descendants * @property Event[]|Collection $events * @property Character[]|Collection $characters diff --git a/app/Services/Entity/Connections/MapService.php b/app/Services/Entity/Connections/MapService.php index 89b471d6e..66a67648b 100644 --- a/app/Services/Entity/Connections/MapService.php +++ b/app/Services/Entity/Connections/MapService.php @@ -666,14 +666,13 @@ protected function addLocation(): self */ protected function addParent(): self { - if (!method_exists($this->entity->child, 'getParentKeyName')) { - // If not part of the node model, check for the {self}_id attribute - if (!array_key_exists($this->entity->type() . '_id', $this->entity->child->getAttributes())) { - return $this; - } + if (!method_exists($this->entity->child, 'parent')) { + return $this; } - $parent = $this->entity->child->parent; + /** @var Location $child */ + $child = $this->entity->child; + $parent = $child->parent; if (empty($parent)) { $this->addChildren(); return $this; @@ -700,12 +699,13 @@ protected function addParent(): self */ protected function addChildren(): self { - /** @var MiscModel $children */ if (!method_exists($this->entity->child, 'children')) { return $this; } - foreach ($this->entity->child->children()->with(['entity', 'entity.image'])->has('entity')->get() as $related) { + /** @var Location $child */ + $child = $this->entity->child; + foreach ($child->children()->with(['entity', 'entity.image'])->has('entity')->get() as $related) { $this->addEntity($related->entity); $this->relations[] = [ 'target' => $this->entity->id, @@ -788,7 +788,7 @@ protected function addMapMarkers(): self */ protected function addMaps(): self { - /** @var Map $parent */ + /** @var Location $parent */ $parent = $this->entity->child; /** @var Map $related */ foreach ($parent->maps()->with(['entity', 'entity.image'])->has('entity')->get() as $related) { @@ -831,7 +831,7 @@ protected function addQuests(): self */ protected function addRaces(): self { - /** @var Race $race */ + /** @var Character $race */ $race = $this->entity->child; foreach ($race->races()->with(['entity', 'entity.image'])->has('entity')->get() as $subrace) {