Skip to content

Commit cbd817d

Browse files
committed
Entities: Addressed phpstan errors
1 parent 49bb5e1 commit cbd817d

File tree

6 files changed

+17
-6
lines changed

6 files changed

+17
-6
lines changed

app/Entities/Models/Entity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public function logDescriptor(): string
451451
}
452452

453453
/**
454-
* @return HasOne<EntityContainerData|EntityPageData, $this>
454+
* @return HasOne<covariant (EntityContainerData|EntityPageData), $this>
455455
*/
456456
abstract public function relatedData(): HasOne;
457457

app/Entities/Models/HasCoverInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function coverInfo(): EntityCover;
1212

1313
/**
1414
* The cover image of this entity.
15-
* @return BelongsTo<Image, $this>
15+
* @return BelongsTo<Image, covariant Entity>
1616
*/
1717
public function cover(): BelongsTo;
1818
}

app/Entities/Tools/EntityCover.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ public function getImage(): Image|null
3737
return null;
3838
}
3939

40-
return $this->imageQuery()->first();
40+
$cover = $this->imageQuery()->first();
41+
if ($cover instanceof Image) {
42+
return $cover;
43+
}
44+
45+
return null;
4146
}
4247

4348
/**

app/Entities/Tools/EntityDefaultTemplate.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@ public function get(): Page|null
4747
}
4848

4949
$pageQueries = app()->make(PageQueries::class);
50-
return $pageQueries->visibleTemplates(true)
50+
$page = $pageQueries->visibleTemplates(true)
5151
->where('id', '=', $this->entity->default_template_id)
5252
->first();
53+
54+
if ($page instanceof Page) {
55+
return $page;
56+
}
57+
58+
return null;
5359
}
5460
}

app/References/ReferenceUpdater.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected function updateReferencesWithinEntity(Entity $entity, string $oldLink,
6969
}
7070
}
7171

72-
protected function updateReferencesWithinDescription(HasDescriptionInterface $entity, string $oldLink, string $newLink): void
72+
protected function updateReferencesWithinDescription(Entity&HasDescriptionInterface $entity, string $oldLink, string $newLink): void
7373
{
7474
$description = $entity->descriptionInfo();
7575
$html = $this->updateLinksInHtml($description->getHtml(true) ?: '', $oldLink, $newLink);

app/Sorting/BookSorter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function runBookAutoSortForAllWithSet(SortRule $set): void
3434
public function runBookAutoSort(Book $book): void
3535
{
3636
$rule = $book->sortRule()->first();
37-
if (!$rule) {
37+
if (!($rule instanceof SortRule)) {
3838
return;
3939
}
4040

0 commit comments

Comments
 (0)