NOW MANAGED ON CODEBERG
Worked towards phpstan level 2, 13 errors remain
Dan Brown2a6533157397
diff --git a/app/Api/ListingResponseBuilder.php b/app/Api/ListingResponseBuilder.phpindex 39752e6d4..44117bad9 100644--- a/app/Api/ListingResponseBuilder.php+++ b/app/Api/ListingResponseBuilder.php@@ -4,21 +4,29 @@ namespace BookStack\Api;use Illuminate\Database\Eloquent\Builder;use Illuminate\Database\Eloquent\Collection;+use Illuminate\Database\Eloquent\Model;use Illuminate\Http\JsonResponse;use Illuminate\Http\Request;class ListingResponseBuilder{- protected $query;- protected $request;- protected $fields;+ protected Builder $query;+ protected Request $request;++ /**+ * @var string[]+ */+ protected array $fields;/*** @var array<callable>*/- protected $resultModifiers = [];+ protected array $resultModifiers = [];- protected $filterOperators = [+ /**+ * @var array<string, string>+ */+ protected array $filterOperators = ['eq' => '=','ne' => '!=','gt' => '>',@@ -62,9 +70,9 @@ class ListingResponseBuilder/*** Add a callback to modify each element of the results.*- * @param (callable(Model)) $modifier+ * @param (callable(Model): void) $modifier*/- public function modifyResults($modifier): void+ public function modifyResults(callable $modifier): void{$this->resultModifiers[] = $modifier;}diff --git a/app/Auth/Permissions/JointPermissionBuilder.php b/app/Auth/Permissions/JointPermissionBuilder.phpindex 129b4a04d..114cff619 100644--- a/app/Auth/Permissions/JointPermissionBuilder.php+++ b/app/Auth/Permissions/JointPermissionBuilder.php@@ -22,7 +22,7 @@ class JointPermissionBuilder/*** @var array<string, array<int, SimpleEntityData>>*/- protected $entityCache;+ protected array $entityCache;/*** Re-generate all entity permission from scratch.@@ -230,7 +230,7 @@ class JointPermissionBuilder/*** Create & Save entity jointPermissions for many entities and roles.*- * @param Entity[] $entities+ * @param Entity[] $originalEntities* @param Role[] $roles*/protected function createManyJointPermissions(array $originalEntities, array $roles)diff --git a/app/Entities/Models/Page.php b/app/Entities/Models/Page.phpindex 7a60b3ada..a224071cc 100644--- a/app/Entities/Models/Page.php+++ b/app/Entities/Models/Page.php@@ -88,8 +88,6 @@ class Page extends BookChild/*** Get the current revision for the page if existing.- *- * @return PageRevision|null*/public function currentRevision(): HasOne{diff --git a/app/Entities/Repos/BaseRepo.php b/app/Entities/Repos/BaseRepo.phpindex da939e102..815c0bb2e 100644--- a/app/Entities/Repos/BaseRepo.php+++ b/app/Entities/Repos/BaseRepo.php@@ -87,14 +87,14 @@ class BaseRepo{if ($coverImage) {$imageType = $entity->coverImageTypeKey();- $this->imageRepo->destroyImage($entity->cover);+ $this->imageRepo->destroyImage($entity->cover()->first());$image = $this->imageRepo->saveNew($coverImage, $imageType, $entity->id, 512, 512, true);$entity->cover()->associate($image);$entity->save();}if ($removeImage) {- $this->imageRepo->destroyImage($entity->cover);+ $this->imageRepo->destroyImage($entity->cover()->first());$entity->image_id = 0;$entity->save();}diff --git a/app/Entities/Tools/BookContents.php b/app/Entities/Tools/BookContents.phpindex 0ad424de2..f45bdfcc1 100644--- a/app/Entities/Tools/BookContents.php+++ b/app/Entities/Tools/BookContents.php@@ -181,7 +181,7 @@ class BookContents$model->changeBook($newBook->id);}- if ($chapterChanged) {+ if ($model instanceof Page && $chapterChanged) {$model->chapter_id = $newChapter->id ?? 0;}@@ -235,7 +235,7 @@ class BookContents}$hasPageEditPermission = userCan('page-update', $model);- $newParentInRightLocation = ($newParent instanceof Book || $newParent->book_id === $newBook->id);+ $newParentInRightLocation = ($newParent instanceof Book || ($newParent instanceof Chapter && $newParent->book_id === $newBook->id));$newParentPermission = ($newParent instanceof Chapter) ? 'chapter-update' : 'book-update';$hasNewParentPermission = userCan($newParentPermission, $newParent);diff --git a/app/Entities/Tools/Cloner.php b/app/Entities/Tools/Cloner.phpindex 52a8f4cf0..5594c33a6 100644--- a/app/Entities/Tools/Cloner.php+++ b/app/Entities/Tools/Cloner.php@@ -7,6 +7,7 @@ use BookStack\Entities\Models\Book;use BookStack\Entities\Models\Bookshelf;use BookStack\Entities\Models\Chapter;use BookStack\Entities\Models\Entity;+use BookStack\Entities\Models\HasCoverImage;use BookStack\Entities\Models\Page;use BookStack\Entities\Repos\BookRepo;use BookStack\Entities\Repos\ChapterRepo;@@ -109,9 +110,11 @@ class Cloner$inputData['tags'] = $this->entityTagsToInputArray($entity);// Add a cover to the data if existing on the original entity- if ($entity->cover instanceof Image) {- $uploadedFile = $this->imageToUploadedFile($entity->cover);- $inputData['image'] = $uploadedFile;+ if ($entity instanceof HasCoverImage) {+ $cover = $entity->cover()->first();+ if ($cover) {+ $inputData['image'] = $this->imageToUploadedFile($cover);+ }}return $inputData;diff --git a/app/Http/Controllers/PageRevisionController.php b/app/Http/Controllers/PageRevisionController.phpindex 89775a602..85ee6c2bc 100644--- a/app/Http/Controllers/PageRevisionController.php+++ b/app/Http/Controllers/PageRevisionController.php@@ -3,6 +3,7 @@namespace BookStack\Http\Controllers;use BookStack\Actions\ActivityType;+use BookStack\Entities\Models\PageRevision;use BookStack\Entities\Repos\PageRepo;use BookStack\Entities\Tools\PageContent;use BookStack\Exceptions\NotFoundException;@@ -50,6 +51,7 @@ class PageRevisionController extends Controllerpublic function show(string $bookSlug, string $pageSlug, int $revisionId){$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);+ /** @var ?PageRevision $revision */$revision = $page->revisions()->where('id', '=', $revisionId)->first();if ($revision === null) {throw new NotFoundException();@@ -78,6 +80,7 @@ class PageRevisionController extends Controllerpublic function changes(string $bookSlug, string $pageSlug, int $revisionId){$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);+ /** @var ?PageRevision $revision */$revision = $page->revisions()->where('id', '=', $revisionId)->first();if ($revision === null) {throw new NotFoundException();diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.phpindex ac3307f2d..415ec6626 100644--- a/app/Providers/RouteServiceProvider.php+++ b/app/Providers/RouteServiceProvider.php@@ -19,14 +19,6 @@ class RouteServiceProvider extends ServiceProvider*/public const HOME = '/';- /**- * This namespace is applied to the controller routes in your routes file.- *- * In addition, it is set as the URL generator's root namespace.- *- * @var string- */-/*** Define your route model bindings, pattern filters, etc.*diff --git a/app/Search/SearchRunner.php b/app/Search/SearchRunner.phpindex cc44e6125..013f7b380 100644--- a/app/Search/SearchRunner.php+++ b/app/Search/SearchRunner.php@@ -50,7 +50,7 @@ class SearchRunner* The provided count is for each entity to search,* Total returned could be larger and not guaranteed.*- * @return array{total: int, count: int, has_more: bool, results: Entity[]}+ * @return array{total: int, count: int, has_more: bool, results: Collection<Entity>}*/public function searchEntities(SearchOptions $searchOpts, string $entityType = 'all', int $page = 1, int $count = 20): array{