From 30b354623927480a98c1577f05775ef2420a2687 Mon Sep 17 00:00:00 2001 From: ilestis Date: Wed, 22 May 2024 14:32:28 -0600 Subject: [PATCH 1/2] Move entry() to parsedEntry() to avoid weird situations --- app/Http/Resources/PostResource.php | 2 +- app/Models/AttributeTemplate.php | 2 +- app/Models/Campaign.php | 4 ++-- app/Models/Conversation.php | 7 ------- app/Models/DiceRoll.php | 2 +- app/Models/Entity.php | 2 +- app/Models/MiscModel.php | 2 +- app/Models/PluginVersion.php | 2 +- app/Models/Post.php | 2 +- app/Models/QuestElement.php | 2 +- app/Models/TimelineElement.php | 2 +- app/Services/Abilities/AbilityService.php | 2 +- app/Services/Abilities/BaseAbilityService.php | 2 +- app/Services/MentionsService.php | 2 +- app/Traits/TooltipTrait.php | 2 +- resources/views/campaigns/show.blade.php | 4 ++-- resources/views/dashboard/widgets/previews/_full.blade.php | 2 +- .../views/dashboard/widgets/previews/_preview.blade.php | 2 +- resources/views/entities/components/_post.blade.php | 2 +- resources/views/entities/components/entry.blade.php | 2 +- .../views/entities/pages/inventory/_inventory.blade.php | 2 +- resources/views/entities/pages/inventory/_item.blade.php | 2 +- resources/views/entities/pages/inventory/details.blade.php | 2 +- resources/views/maps/markers/details.blade.php | 2 +- resources/views/maps/markers/dialog_details.blade.php | 2 +- resources/views/quests/elements/_elements.blade.php | 2 +- resources/views/timelines/_element.blade.php | 2 +- 27 files changed, 28 insertions(+), 35 deletions(-) diff --git a/app/Http/Resources/PostResource.php b/app/Http/Resources/PostResource.php index 7b415a1a79..4ed14c5540 100644 --- a/app/Http/Resources/PostResource.php +++ b/app/Http/Resources/PostResource.php @@ -20,7 +20,7 @@ public function toArray($request) 'name' => $model->name, 'visibility_id' => (int) $model->visibility_id->value, 'entry' => $model->entry, - 'entry_parsed' => $model->entry(), + 'entry_parsed' => $model->parsedEntry(), // 'is_pinned' => (bool) $this->is_pinned, 'position' => $model->position, 'settings' => $model->settings, diff --git a/app/Models/AttributeTemplate.php b/app/Models/AttributeTemplate.php index ead3c6f499..9b65d07693 100644 --- a/app/Models/AttributeTemplate.php +++ b/app/Models/AttributeTemplate.php @@ -219,7 +219,7 @@ public function hasVisibleAttributes($names = []): bool * Attribute Templates have no entry field * @return mixed|string */ - public function entry() + public function parsedEntry() { return ''; } diff --git a/app/Models/Campaign.php b/app/Models/Campaign.php index b2c236c35b..f1b4edb98a 100644 --- a/app/Models/Campaign.php +++ b/app/Models/Campaign.php @@ -131,7 +131,7 @@ public function preview(): string return $this->excerpt(); } if (!empty(strip_tags($this->entry))) { - return strip_tags(mb_substr($this->entry(), 0, 1000)) . ' ...'; + return strip_tags(mb_substr($this->parsedEntry(), 0, 1000)) . ' ...'; } return ''; } @@ -261,7 +261,7 @@ public function isHidden(): bool /** */ - public function entry() + public function parsedEntry() { return Mentions::mapAny($this); } diff --git a/app/Models/Conversation.php b/app/Models/Conversation.php index 1302bbdbbc..1778a993a5 100644 --- a/app/Models/Conversation.php +++ b/app/Models/Conversation.php @@ -123,13 +123,6 @@ public function entityTypeId(): int return (int) config('entities.ids.conversation'); } - /** - */ - public function entry() - { - return ''; - } - /** */ public function forCharacters(): bool diff --git a/app/Models/DiceRoll.php b/app/Models/DiceRoll.php index 89da267ec7..64d6679c84 100644 --- a/app/Models/DiceRoll.php +++ b/app/Models/DiceRoll.php @@ -86,7 +86,7 @@ public function entityTypeId(): int /** * @return mixed|string */ - public function entry() + public function parsedEntry() { return ''; } diff --git a/app/Models/Entity.php b/app/Models/Entity.php index 52fbc8f732..5a202b74e2 100644 --- a/app/Models/Entity.php +++ b/app/Models/Entity.php @@ -191,7 +191,7 @@ public function mappedPreview(): string return (string)strip_tags($text); } } - return Str::limit(strip_tags($this->child->entry()), 500); + return Str::limit(strip_tags($this->child->parsedEntry()), 500); } diff --git a/app/Models/MiscModel.php b/app/Models/MiscModel.php index cb19288887..f56ac8c132 100644 --- a/app/Models/MiscModel.php +++ b/app/Models/MiscModel.php @@ -191,7 +191,7 @@ public function entityTypeSuggestion(int $take = 20): array /** */ - public function entry() + public function parsedEntry() { return Mentions::map($this); } diff --git a/app/Models/PluginVersion.php b/app/Models/PluginVersion.php index 625177d4fa..0739af9235 100644 --- a/app/Models/PluginVersion.php +++ b/app/Models/PluginVersion.php @@ -516,7 +516,7 @@ protected function abilities(Entity $entity): array 'name' => $abi->ability->name, 'slug' => $abi->ability->slug, 'type' => $abi->ability->type, - 'entry' => $abi->ability->entry(), + 'entry' => $abi->ability->parsedEntry(), 'charges' => $abi->ability->charges, 'used_charges' => $abi->charges, 'thumb' => '', diff --git a/app/Models/Post.php b/app/Models/Post.php index 1070f49d16..3cad37dae0 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -144,7 +144,7 @@ public function copyTo(Entity $target) /** */ - public function entry() + public function parsedEntry() { return Mentions::mapPost($this); } diff --git a/app/Models/QuestElement.php b/app/Models/QuestElement.php index 3b077303f9..3c04aa4084 100644 --- a/app/Models/QuestElement.php +++ b/app/Models/QuestElement.php @@ -63,7 +63,7 @@ public function entity() /** */ - public function entry() + public function parsedEntry() { return Mentions::mapAny($this, 'description'); } diff --git a/app/Models/TimelineElement.php b/app/Models/TimelineElement.php index 1cb1efaa02..548f534e2a 100644 --- a/app/Models/TimelineElement.php +++ b/app/Models/TimelineElement.php @@ -113,7 +113,7 @@ public function getEntryForEditionAttribute() /** */ - public function entry() + public function parsedEntry() { return Mentions::mapAny($this); } diff --git a/app/Services/Abilities/AbilityService.php b/app/Services/Abilities/AbilityService.php index 163bfd9aa3..82180fd3c3 100644 --- a/app/Services/Abilities/AbilityService.php +++ b/app/Services/Abilities/AbilityService.php @@ -91,7 +91,7 @@ protected function add(EntityAbility $entityAbility): void 'type' => $parent->type, 'image' => Avatar::entity($parent->entity)->size(192)->thumbnail(), 'has_image' => !empty($parent->entity->image_path) || !empty($parent->entity->image), - 'entry' => $parent->entry(), + 'entry' => $parent->parsedEntry(), 'parent' => true, 'abilities' => [], 'url' => $parent->getLink(), diff --git a/app/Services/Abilities/BaseAbilityService.php b/app/Services/Abilities/BaseAbilityService.php index 24c8133f19..7696e56434 100644 --- a/app/Services/Abilities/BaseAbilityService.php +++ b/app/Services/Abilities/BaseAbilityService.php @@ -39,7 +39,7 @@ protected function parseCharges(Ability $ability) */ protected function parseEntry(Ability $ability) { - $entry = $ability->entry(); + $entry = $ability->parsedEntry(); try { return $this->mapAttributes($entry, false); } catch (Exception $e) { diff --git a/app/Services/MentionsService.php b/app/Services/MentionsService.php index 704de9f54a..d83742cfe0 100644 --- a/app/Services/MentionsService.php +++ b/app/Services/MentionsService.php @@ -383,7 +383,7 @@ protected function replaceEntityMentions(): void if ($field === 'entry') { if ($this->enableEntryField) { $this->lockEntryRendering(); - $parsedTargetEntry = $entity->child->entry(); + $parsedTargetEntry = $entity->child->parsedEntry(); $this->unlockEntryRendering(); } else { $parsedTargetEntry = $entity->child->entry; diff --git a/app/Traits/TooltipTrait.php b/app/Traits/TooltipTrait.php index aa8a6e6d6d..dc85a29981 100644 --- a/app/Traits/TooltipTrait.php +++ b/app/Traits/TooltipTrait.php @@ -52,7 +52,7 @@ public function ajaxTooltip(): string /** @var MiscModel $child */ $child = $this->child; - $text = $child->entry(); + $text = $child->parsedEntry(); $text = strip_tags($text, $this->allowedTooltipTags()); $text = Str::limit($text, 500); return $text; diff --git a/resources/views/campaigns/show.blade.php b/resources/views/campaigns/show.blade.php index da2beab797..3b6231fc50 100644 --- a/resources/views/campaigns/show.blade.php +++ b/resources/views/campaigns/show.blade.php @@ -61,13 +61,13 @@
- @if (auth()->check() && auth()->user()->can('update', $campaign) && empty($campaign->entry())) + @if (auth()->check() && auth()->user()->can('update', $campaign) && empty($campaign->entry)) {{ __('campaigns.helpers.no_entry') }} @else
- {!! $campaign->entry() !!} + {!! $campaign->parsedEntry() !!}
@endif
diff --git a/resources/views/dashboard/widgets/previews/_full.blade.php b/resources/views/dashboard/widgets/previews/_full.blade.php index 21159eee55..85294aa20b 100644 --- a/resources/views/dashboard/widgets/previews/_full.blade.php +++ b/resources/views/dashboard/widgets/previews/_full.blade.php @@ -1,7 +1,7 @@ {!! $slot !!}
- {!! $model->entry() !!} + {!! $model->parsedEntry() !!}
@include('dashboard.widgets.previews._members') diff --git a/resources/views/dashboard/widgets/previews/_preview.blade.php b/resources/views/dashboard/widgets/previews/_preview.blade.php index efeebf1d21..92ac5ab2a4 100644 --- a/resources/views/dashboard/widgets/previews/_preview.blade.php +++ b/resources/views/dashboard/widgets/previews/_preview.blade.php @@ -1,7 +1,7 @@
{!! $slot !!}
- {!! $model->entry() !!} + {!! $model->parsedEntry() !!}
@include('dashboard.widgets.previews._members') diff --git a/resources/views/entities/components/_post.blade.php b/resources/views/entities/components/_post.blade.php index b44f6bf14a..d5b02e423e 100644 --- a/resources/views/entities/components/_post.blade.php +++ b/resources/views/entities/components/_post.blade.php @@ -46,7 +46,7 @@ @endif
- {!! $post->entry() !!} + {!! $post->parsedEntry() !!}
@endcan @endif - {!! $model->entry() !!} + {!! $model->parsedEntry() !!}
@endif diff --git a/resources/views/entities/pages/inventory/_inventory.blade.php b/resources/views/entities/pages/inventory/_inventory.blade.php index fee244e9d5..b371f923c3 100644 --- a/resources/views/entities/pages/inventory/_inventory.blade.php +++ b/resources/views/entities/pages/inventory/_inventory.blade.php @@ -53,7 +53,7 @@ @endif
@if ($item->item && $item->copy_item_entry) - {!! $item->item->entry() !!} + {!! $item->item->parsedEntry() !!} @else {{ $item->description }} @endif diff --git a/resources/views/entities/pages/inventory/_item.blade.php b/resources/views/entities/pages/inventory/_item.blade.php index 0f4b9bb909..ae2fb4b2d0 100644 --- a/resources/views/entities/pages/inventory/_item.blade.php +++ b/resources/views/entities/pages/inventory/_item.blade.php @@ -23,7 +23,7 @@

@if ($item->item && $item->copy_item_entry) - {!! \Illuminate\Support\Str::limit(strip_tags($item->item->entry()), 100) !!} + {!! \Illuminate\Support\Str::limit(strip_tags($item->item->parsedEntry()), 100) !!} @else {!! \Illuminate\Support\Str::limit($item->description, 100) !!} @endif diff --git a/resources/views/entities/pages/inventory/details.blade.php b/resources/views/entities/pages/inventory/details.blade.php index 74ef3f7c3b..8224b99be5 100644 --- a/resources/views/entities/pages/inventory/details.blade.php +++ b/resources/views/entities/pages/inventory/details.blade.php @@ -101,7 +101,7 @@

@if ($inventory->item && $inventory->copy_item_entry) - {!! $inventory->item->entry() !!} + {!! $inventory->item->parsedEntry() !!} @else {!! $inventory->description !!} @endif diff --git a/resources/views/maps/markers/details.blade.php b/resources/views/maps/markers/details.blade.php index d89a0fc7d3..31fab2ebaa 100644 --- a/resources/views/maps/markers/details.blade.php +++ b/resources/views/maps/markers/details.blade.php @@ -67,7 +67,7 @@ @endif @if ($marker->entity && $marker->entity->child->hasEntry())

- {!! $marker->entity->child->entry() !!} + {!! $marker->entity->child->parsedEntry() !!}
@endif diff --git a/resources/views/maps/markers/dialog_details.blade.php b/resources/views/maps/markers/dialog_details.blade.php index 0cb897d2e5..12d1b85646 100644 --- a/resources/views/maps/markers/dialog_details.blade.php +++ b/resources/views/maps/markers/dialog_details.blade.php @@ -9,7 +9,7 @@ @endif @if ($marker->entity && $marker->entity->child->hasEntry())
- {!! $marker->entity->child->entry() !!} + {!! $marker->entity->child->parsedEntry() !!}
@endif diff --git a/resources/views/quests/elements/_elements.blade.php b/resources/views/quests/elements/_elements.blade.php index f9a48b67a9..7b3133c5dd 100644 --- a/resources/views/quests/elements/_elements.blade.php +++ b/resources/views/quests/elements/_elements.blade.php @@ -35,7 +35,7 @@
- {!! $element->entry() !!} + {!! $element->parsedEntry() !!}
diff --git a/resources/views/timelines/_element.blade.php b/resources/views/timelines/_element.blade.php index 08113d7b6d..316a33b257 100644 --- a/resources/views/timelines/_element.blade.php +++ b/resources/views/timelines/_element.blade.php @@ -79,7 +79,7 @@ @if ($element->use_entity_entry && $element->entity && $element->entity->child->hasEntry())
- {!! $element->entity->child->entry() !!} + {!! $element->entity->child->parsedEntry() !!}
@endif
From c86e18eeb3acac23ac9400b4a4f9e9f0b0b1aebd Mon Sep 17 00:00:00 2001 From: ilestis Date: Wed, 22 May 2024 14:51:34 -0600 Subject: [PATCH 2/2] PHPStan was a mistake --- app/Models/EntityEvent.php | 12 +++++++----- app/Models/EntityLog.php | 2 +- app/Models/Relations/EntityRelations.php | 3 +++ app/Services/Submenus/AbilitySubmenu.php | 9 ++++++--- app/Services/Submenus/BaseSubmenu.php | 5 +++-- app/Services/Submenus/CalendarSubmenu.php | 6 +++++- app/Services/Submenus/CharacterSubmenu.php | 11 +++++++---- app/Services/Submenus/CreatureSubmenu.php | 7 +++++-- app/Services/Submenus/EventSubmenu.php | 7 +++++-- app/Services/Submenus/FamilySubmenu.php | 7 +++++-- app/Services/Submenus/ItemSubmenu.php | 6 +++++- app/Services/Submenus/JournalSubmenu.php | 7 +++++-- app/Services/Submenus/LocationSubmenu.php | 10 +++++++--- app/Services/Submenus/MapSubmenu.php | 15 +++++++++------ app/Services/Submenus/OrganisationSubmenu.php | 8 +++++--- app/Services/Submenus/QuestSubmenu.php | 6 +++++- app/Services/Submenus/RaceSubmenu.php | 7 +++++-- app/Services/Submenus/SubmenuService.php | 10 ++++++---- app/Services/Submenus/TagSubmenu.php | 7 +++++-- app/Services/Submenus/TimelineSubmenu.php | 11 +++++++---- 20 files changed, 106 insertions(+), 50 deletions(-) diff --git a/app/Models/EntityEvent.php b/app/Models/EntityEvent.php index d836d547a9..5dc751d8ca 100644 --- a/app/Models/EntityEvent.php +++ b/app/Models/EntityEvent.php @@ -7,6 +7,7 @@ use Exception; use App\Models\Concerns\SortableTrait; use App\Traits\VisibilityIDTrait; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -15,6 +16,7 @@ * Class EntityEvent * @package App\Models * + * @property int $id * @property int $entity_id * @property int $calendar_id * @property string $date @@ -34,7 +36,7 @@ * @property EntityEvent|null $death * @property EntityEventType|null $type */ -class EntityEvent extends MiscModel +class EntityEvent extends Model { use Blameable; use EntityEventScopes; @@ -45,8 +47,8 @@ class EntityEvent extends MiscModel /** @var string */ public $table = 'entity_events'; - /** @var string|null Cached readable date */ - protected string|null $readableDate = null; + /** @var string Cached readable date */ + protected string $readableDate; protected $fillable = [ 'calendar_id', @@ -85,7 +87,7 @@ public function calendar(): BelongsTo return $this->belongsTo(Calendar::class, 'calendar_id'); } - public function entity() + public function entity(): BelongsTo { return $this->belongsTo(Entity::class, 'entity_id'); } @@ -99,7 +101,7 @@ public function type(): BelongsTo */ public function readableDate(): string { - if ($this->readableDate === null) { + if (!isset($this->readableDate)) { // Replace month with real month, and year maybe $months = $this->calendar->months(); $years = $this->calendar->years(); diff --git a/app/Models/EntityLog.php b/app/Models/EntityLog.php index f469249083..a418f48139 100644 --- a/app/Models/EntityLog.php +++ b/app/Models/EntityLog.php @@ -21,7 +21,7 @@ * @property int $impersonated_by * @property int $action * @property int $post_id - * @property string|array $changes + * @property null|string|array $changes * @property Entity|null $entity * @property User|null $user * @property User|null $impersonator diff --git a/app/Models/Relations/EntityRelations.php b/app/Models/Relations/EntityRelations.php index bf738f8f53..708828612f 100644 --- a/app/Models/Relations/EntityRelations.php +++ b/app/Models/Relations/EntityRelations.php @@ -186,6 +186,9 @@ public function tags(): BelongsToMany ); } + /** + * @return Collection|Tag[] + */ public function tagsWithEntity(bool $excludeHidden = false): Collection { if (!isset($this->tagsWithEntity)) { diff --git a/app/Services/Submenus/AbilitySubmenu.php b/app/Services/Submenus/AbilitySubmenu.php index fbe1e0b5bd..842b90cc75 100644 --- a/app/Services/Submenus/AbilitySubmenu.php +++ b/app/Services/Submenus/AbilitySubmenu.php @@ -3,21 +3,24 @@ namespace App\Services\Submenus; use App\Facades\Module; +use App\Models\Ability; class AbilitySubmenu extends BaseSubmenu implements EntitySubmenu { public function extra(): array { $items = []; + /** @var Ability $ability */ + $ability = $this->model; $items['second']['abilities'] = [ - 'name' => Module::plural($this->model->entityTypeId(), 'entities.abilities'), + 'name' => Module::plural($ability->entityTypeId(), 'entities.abilities'), 'route' => 'abilities.abilities', - 'count' => $this->model->descendants()->count() + 'count' => $ability->descendants()->count() ]; $items['second']['entities'] = [ 'name' => 'abilities.show.tabs.entities', 'route' => 'abilities.entities', - 'count' => $this->model->entities()->count() + 'count' => $ability->entities()->count() ]; return $items; } diff --git a/app/Services/Submenus/BaseSubmenu.php b/app/Services/Submenus/BaseSubmenu.php index 03173f9b82..5d78ae2b74 100644 --- a/app/Services/Submenus/BaseSubmenu.php +++ b/app/Services/Submenus/BaseSubmenu.php @@ -2,6 +2,7 @@ namespace App\Services\Submenus; +use App\Models\MiscModel; use App\Traits\CampaignAware; use Illuminate\Database\Eloquent\Model; @@ -10,9 +11,9 @@ class BaseSubmenu use CampaignAware; protected array $items; - protected Model $model; + protected Model|MiscModel $model; - public function model(Model $model): self + public function model(Model|MiscModel $model): self { $this->model = $model; return $this; diff --git a/app/Services/Submenus/CalendarSubmenu.php b/app/Services/Submenus/CalendarSubmenu.php index 0eca5aec8f..77c864a093 100644 --- a/app/Services/Submenus/CalendarSubmenu.php +++ b/app/Services/Submenus/CalendarSubmenu.php @@ -2,11 +2,15 @@ namespace App\Services\Submenus; +use App\Models\Calendar; + class CalendarSubmenu extends BaseSubmenu implements EntitySubmenu { public function extra(): array { - $count = $this->model->calendarEvents()->has('entity')->count(); + /** @var Calendar $calendar */ + $calendar = $this->model; + $count = $calendar->calendarEvents()->has('entity')->count(); $items = []; if ($count > 0) { $items['second']['events'] = [ diff --git a/app/Services/Submenus/CharacterSubmenu.php b/app/Services/Submenus/CharacterSubmenu.php index 5d1f605274..b590010353 100644 --- a/app/Services/Submenus/CharacterSubmenu.php +++ b/app/Services/Submenus/CharacterSubmenu.php @@ -4,27 +4,30 @@ use App\Facades\CampaignLocalization; use App\Facades\Module; +use App\Models\Character; class CharacterSubmenu extends BaseSubmenu implements EntitySubmenu { public function extra(): array { $items = []; - $canEdit = auth()->check() && auth()->user()->can('update', $this->model); + /** @var Character $character */ + $character = $this->model; + $canEdit = auth()->check() && auth()->user()->can('update', $character); $items['second']['profile'] = [ 'name' => 'entities/profile.show.tab_name', 'route' => 'entities.profile', 'entity' => true, - 'button' => auth()->check() && auth()->user()->can('update', $this->model) ? [ - 'url' => $this->model->getLink('edit'), + 'button' => auth()->check() && auth()->user()->can('update', $character) ? [ + 'url' => $character->getLink('edit'), 'icon' => 'fa-solid fa-pencil', 'tooltip' => __('crud.edit'), ] : null, ]; - $count = $this->model->organisationMemberships()->has('organisation')->count(); + $count = $character->organisationMemberships()->has('organisation')->count(); if ($this->campaign->enabled('organisations') && ($count > 0 || $canEdit)) { $items['second']['organisations'] = [ 'name' => Module::plural(config('entities.ids.organisation'), 'entities.organisations'), diff --git a/app/Services/Submenus/CreatureSubmenu.php b/app/Services/Submenus/CreatureSubmenu.php index f4339958c4..12519e9374 100644 --- a/app/Services/Submenus/CreatureSubmenu.php +++ b/app/Services/Submenus/CreatureSubmenu.php @@ -3,16 +3,19 @@ namespace App\Services\Submenus; use App\Facades\Module; +use App\Models\Creature; class CreatureSubmenu extends BaseSubmenu implements EntitySubmenu { public function extra(): array { $items = []; - $count = $this->model->descendants()->count(); + /** @var Creature $creature */ + $creature = $this->model; + $count = $creature->descendants()->count(); if ($count > 0) { $items['second']['creatures'] = [ - 'name' => Module::plural($this->model->entityTypeId(), 'entities.creatures'), + 'name' => Module::plural($creature->entityTypeId(), 'entities.creatures'), 'route' => 'creatures.creatures', 'count' => $count ]; diff --git a/app/Services/Submenus/EventSubmenu.php b/app/Services/Submenus/EventSubmenu.php index 0f8a5393bd..ca6aafbf92 100644 --- a/app/Services/Submenus/EventSubmenu.php +++ b/app/Services/Submenus/EventSubmenu.php @@ -3,16 +3,19 @@ namespace App\Services\Submenus; use App\Facades\Module; +use App\Models\Event; class EventSubmenu extends BaseSubmenu implements EntitySubmenu { public function extra(): array { $items = []; + /** @var Event $event */ + $event = $this->model; $items['second']['events'] = [ - 'name' => Module::plural($this->model->entityTypeId(), 'entities.events'), + 'name' => Module::plural($event->entityTypeId(), 'entities.events'), 'route' => 'events.events', - 'count' => $this->model->descendants()->count() + 'count' => $event->descendants()->count() ]; return $items; } diff --git a/app/Services/Submenus/FamilySubmenu.php b/app/Services/Submenus/FamilySubmenu.php index d3b0a46aae..43e603ea1f 100644 --- a/app/Services/Submenus/FamilySubmenu.php +++ b/app/Services/Submenus/FamilySubmenu.php @@ -3,16 +3,19 @@ namespace App\Services\Submenus; use App\Facades\Module; +use App\Models\Family; class FamilySubmenu extends BaseSubmenu implements EntitySubmenu { public function extra(): array { $items = []; + /** @var Family $family */ + $family = $this->model; $items['second']['families'] = [ - 'name' => Module::plural($this->model->entityTypeId(), 'entities.families'), + 'name' => Module::plural($family->entityTypeId(), 'entities.families'), 'route' => 'families.families', - 'count' => $this->model->descendants()->count() + 'count' => $family->descendants()->count() ]; if (config('services.stripe.enabled')) { diff --git a/app/Services/Submenus/ItemSubmenu.php b/app/Services/Submenus/ItemSubmenu.php index 34f13d9487..4bfe353b84 100644 --- a/app/Services/Submenus/ItemSubmenu.php +++ b/app/Services/Submenus/ItemSubmenu.php @@ -2,12 +2,16 @@ namespace App\Services\Submenus; +use App\Models\Item; + class ItemSubmenu extends BaseSubmenu implements EntitySubmenu { public function extra(): array { $items = []; - $inventoryCount = $this->model->inventories()->with('item')->has('entity')->count(); + /** @var Item $item */ + $item = $this->model; + $inventoryCount = $item->inventories()->with('item')->has('entity')->count(); if ($inventoryCount > 0) { $items['second']['inventories'] = [ 'name' => 'items.show.tabs.inventories', diff --git a/app/Services/Submenus/JournalSubmenu.php b/app/Services/Submenus/JournalSubmenu.php index 9fa0fd8377..d9726cef1c 100644 --- a/app/Services/Submenus/JournalSubmenu.php +++ b/app/Services/Submenus/JournalSubmenu.php @@ -3,16 +3,19 @@ namespace App\Services\Submenus; use App\Facades\Module; +use App\Models\Journal; class JournalSubmenu extends BaseSubmenu implements EntitySubmenu { public function extra(): array { $items = []; + /** @var Journal $journal */ + $journal = $this->model; $items['second']['journals'] = [ - 'name' => Module::plural($this->model->entityTypeId(), 'entities.journals'), + 'name' => Module::plural($journal->entityTypeId(), 'entities.journals'), 'route' => 'journals.journals', - 'count' => $this->model->descendants()->count() + 'count' => $journal->descendants()->count() ]; return $items; } diff --git a/app/Services/Submenus/LocationSubmenu.php b/app/Services/Submenus/LocationSubmenu.php index 7c2a8393c2..d78df39778 100644 --- a/app/Services/Submenus/LocationSubmenu.php +++ b/app/Services/Submenus/LocationSubmenu.php @@ -4,23 +4,27 @@ use App\Facades\CampaignLocalization; use App\Facades\Module; +use App\Models\Location; class LocationSubmenu extends BaseSubmenu implements EntitySubmenu { public function extra(): array { $items = []; + /** @var Location $location */ + $location = $this->model; - $count = $this->model->descendants()->has('location')->count(); + // @phpstan-ignore-next-line + $count = $location->descendants()->has('location')->count(); if ($count > 0) { $items['second']['locations'] = [ - 'name' => Module::plural($this->model->entityTypeId(), 'entities.locations'), + 'name' => Module::plural($location->entityTypeId(), 'entities.locations'), 'route' => 'locations.locations', 'count' => $count ]; } - $count = $this->model->allCharacters()->count(); + $count = $location->allCharacters()->count(); if ($this->campaign->enabled('characters') && $count > 0) { $items['second']['characters'] = [ 'name' => Module::plural(config('entities.ids.character'), 'entities.characters'), diff --git a/app/Services/Submenus/MapSubmenu.php b/app/Services/Submenus/MapSubmenu.php index 43ccb62d8e..78f1d33052 100644 --- a/app/Services/Submenus/MapSubmenu.php +++ b/app/Services/Submenus/MapSubmenu.php @@ -3,32 +3,35 @@ namespace App\Services\Submenus; use App\Facades\Module; +use App\Models\Map; class MapSubmenu extends BaseSubmenu implements EntitySubmenu { public function extra(): array { $items = []; + /** @var Map $map */ + $map = $this->model; $items['second']['maps'] = [ - 'name' => Module::plural($this->model->entityTypeId(), 'entities.maps'), + 'name' => Module::plural($map->entityTypeId(), 'entities.maps'), 'route' => 'maps.maps', - 'count' => $this->model->maps()->count() + 'count' => $map->maps()->count() ]; - if (auth()->check() && auth()->user()->can('update', $this->model)) { + if (auth()->check() && auth()->user()->can('update', $map)) { $items['second']['layers'] = [ 'name' => 'maps.panels.layers', 'route' => 'maps.map_layers.index', - 'count' => $this->model->layers->count() + 'count' => $map->layers->count() ]; $items['second']['groups'] = [ 'name' => 'maps.panels.groups', 'route' => 'maps.map_groups.index', - 'count' => $this->model->groups->count() + 'count' => $map->groups->count() ]; $items['second']['markers'] = [ 'name' => 'maps.panels.markers', 'route' => 'maps.map_markers.index', - 'count' => $this->model->markers->count() + 'count' => $map->markers->count() ]; } return $items; diff --git a/app/Services/Submenus/OrganisationSubmenu.php b/app/Services/Submenus/OrganisationSubmenu.php index c1ae57f1ec..353d2ab8df 100644 --- a/app/Services/Submenus/OrganisationSubmenu.php +++ b/app/Services/Submenus/OrganisationSubmenu.php @@ -3,17 +3,19 @@ namespace App\Services\Submenus; use App\Facades\Module; +use App\Models\Organisation; class OrganisationSubmenu extends BaseSubmenu implements EntitySubmenu { public function extra(): array { $items = []; - - $count = $this->model->descendants()->count(); + /** @var Organisation $model */ + $model = $this->model; + $count = $model->descendants()->count(); if ($count > 0) { $items['second']['organisations'] = [ - 'name' => Module::plural($this->model->entityTypeId(), 'entities.organisations'), + 'name' => Module::plural($model->entityTypeId(), 'entities.organisations'), 'route' => 'organisations.organisations', 'count' => $count, ]; diff --git a/app/Services/Submenus/QuestSubmenu.php b/app/Services/Submenus/QuestSubmenu.php index 4ab0efbee6..202aea95cd 100644 --- a/app/Services/Submenus/QuestSubmenu.php +++ b/app/Services/Submenus/QuestSubmenu.php @@ -2,12 +2,16 @@ namespace App\Services\Submenus; +use App\Models\Quest; + class QuestSubmenu extends BaseSubmenu implements EntitySubmenu { public function extra(): array { $items = []; - $count = $this->model->elements()->with('entity')->has('entity')->count(); + /** @var Quest $model */ + $model = $this->model; + $count = $model->elements()->with('entity')->has('entity')->count(); $items['second']['elements'] = [ 'name' => 'quests.show.tabs.elements', 'route' => 'quests.quest_elements.index', diff --git a/app/Services/Submenus/RaceSubmenu.php b/app/Services/Submenus/RaceSubmenu.php index 550d36ce93..85c66a0db0 100644 --- a/app/Services/Submenus/RaceSubmenu.php +++ b/app/Services/Submenus/RaceSubmenu.php @@ -3,16 +3,19 @@ namespace App\Services\Submenus; use App\Facades\Module; +use App\Models\Race; class RaceSubmenu extends BaseSubmenu implements EntitySubmenu { public function extra(): array { $items = []; - $count = $this->model->descendants()->count(); + /** @var Race $model */ + $model = $this->model; + $count = $model->descendants()->count(); if ($count > 0) { $items['second']['races'] = [ - 'name' => Module::plural($this->model->entityTypeId(), 'entities.races'), + 'name' => Module::plural($model->entityTypeId(), 'entities.races'), 'route' => 'races.races', 'count' => $count ]; diff --git a/app/Services/Submenus/SubmenuService.php b/app/Services/Submenus/SubmenuService.php index dff842f36a..4afab64b7a 100644 --- a/app/Services/Submenus/SubmenuService.php +++ b/app/Services/Submenus/SubmenuService.php @@ -3,6 +3,7 @@ namespace App\Services\Submenus; use App\Facades\Module; +use App\Models\MiscModel; use App\Traits\CampaignAware; use App\Traits\EntityAware; use Illuminate\Database\Eloquent\Model; @@ -14,11 +15,11 @@ class SubmenuService use CampaignAware; use EntityAware; - protected Model $model; + protected Model|MiscModel $model; protected array $items = []; protected array $ordered; - public function model(Model $model): self + public function model(Model|MiscModel $model): self { $this->model = $model; return $this; @@ -57,6 +58,7 @@ protected function default(): self } // Each entity can have abilities + // @phpstan-ignore-next-line if ($this->campaign->enabled('abilities') && $this->model->entityTypeId() != config('entities.ids.ability')) { $this->items['third']['abilities'] = [ 'name' => Module::plural(config('entities.ids.ability'), 'crud.tabs.abilities'), @@ -141,9 +143,9 @@ protected function custom(): self $className = Str::afterLast(get_class($this->model), '\\'); $submenuName = 'App\Services\Submenus\\' . $className . 'Submenu'; try { - /** @var BaseSubmenu $object */ + /** @var CharacterSubmenu $object */ $object = app()->make($submenuName); - //$this->items = array_merge($this->items, $object->model($this->model)->extra()); + // @phpstan-ignore-next-line $this->items += $object->model($this->model)->campaign($this->campaign)->extra(); } catch (\Exception $e) { // Some modules like convos have no submenu diff --git a/app/Services/Submenus/TagSubmenu.php b/app/Services/Submenus/TagSubmenu.php index 4ab27fb7ef..595370f1dc 100644 --- a/app/Services/Submenus/TagSubmenu.php +++ b/app/Services/Submenus/TagSubmenu.php @@ -3,6 +3,7 @@ namespace App\Services\Submenus; use App\Facades\Module; +use App\Models\Tag; class TagSubmenu extends BaseSubmenu implements EntitySubmenu { @@ -10,10 +11,12 @@ public function extra(): array { $items = []; - $count = $this->model->descendants->count(); + /** @var Tag $model */ + $model = $this->model; + $count = $model->descendants->count(); if ($count > 0) { $items['second']['tags'] = [ - 'name' => Module::plural($this->model->entityTypeId(), 'entities.tags'), + 'name' => Module::plural($model->entityTypeId(), 'entities.tags'), 'route' => 'tags.tags', 'count' => $count, ]; diff --git a/app/Services/Submenus/TimelineSubmenu.php b/app/Services/Submenus/TimelineSubmenu.php index 3f16b89d58..ef116a18f8 100644 --- a/app/Services/Submenus/TimelineSubmenu.php +++ b/app/Services/Submenus/TimelineSubmenu.php @@ -3,22 +3,25 @@ namespace App\Services\Submenus; use App\Facades\Module; +use App\Models\Timeline; class TimelineSubmenu extends BaseSubmenu implements EntitySubmenu { public function extra(): array { $items = []; + /** @var Timeline $model */ + $model = $this->model; $items['second']['timelines'] = [ - 'name' => Module::plural($this->model->entityTypeId(), 'entities.timelines'), + 'name' => Module::plural($model->entityTypeId(), 'entities.timelines'), 'route' => 'timelines.timelines', - 'count' => $this->model->descendants()->count() + 'count' => $model->descendants()->count() ]; - if (auth()->check() && auth()->user()->can('update', $this->model)) { + if (auth()->check() && auth()->user()->can('update', $model)) { $items['second']['eras'] = [ 'name' => 'timelines.fields.eras', 'route' => 'timelines.timeline_eras.index', - 'count' => $this->model->eras->count() + 'count' => $model->eras->count() ]; $items['second']['reorder'] = [ 'name' => 'timelines.show.tabs.reorder',