mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-10 02:21:23 +03:00
Worked towards phpstan level 2, 13 errors remain
This commit is contained in:
@ -4,21 +4,29 @@ namespace BookStack\Api;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class ListingResponseBuilder
|
class ListingResponseBuilder
|
||||||
{
|
{
|
||||||
protected $query;
|
protected Builder $query;
|
||||||
protected $request;
|
protected Request $request;
|
||||||
protected $fields;
|
|
||||||
|
/**
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
protected array $fields;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array<callable>
|
* @var array<callable>
|
||||||
*/
|
*/
|
||||||
protected $resultModifiers = [];
|
protected array $resultModifiers = [];
|
||||||
|
|
||||||
protected $filterOperators = [
|
/**
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
protected array $filterOperators = [
|
||||||
'eq' => '=',
|
'eq' => '=',
|
||||||
'ne' => '!=',
|
'ne' => '!=',
|
||||||
'gt' => '>',
|
'gt' => '>',
|
||||||
@ -62,9 +70,9 @@ class ListingResponseBuilder
|
|||||||
/**
|
/**
|
||||||
* Add a callback to modify each element of the results.
|
* 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;
|
$this->resultModifiers[] = $modifier;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ class JointPermissionBuilder
|
|||||||
/**
|
/**
|
||||||
* @var array<string, array<int, SimpleEntityData>>
|
* @var array<string, array<int, SimpleEntityData>>
|
||||||
*/
|
*/
|
||||||
protected $entityCache;
|
protected array $entityCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Re-generate all entity permission from scratch.
|
* Re-generate all entity permission from scratch.
|
||||||
@ -230,7 +230,7 @@ class JointPermissionBuilder
|
|||||||
/**
|
/**
|
||||||
* Create & Save entity jointPermissions for many entities and roles.
|
* Create & Save entity jointPermissions for many entities and roles.
|
||||||
*
|
*
|
||||||
* @param Entity[] $entities
|
* @param Entity[] $originalEntities
|
||||||
* @param Role[] $roles
|
* @param Role[] $roles
|
||||||
*/
|
*/
|
||||||
protected function createManyJointPermissions(array $originalEntities, array $roles)
|
protected function createManyJointPermissions(array $originalEntities, array $roles)
|
||||||
|
@ -88,8 +88,6 @@ class Page extends BookChild
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current revision for the page if existing.
|
* Get the current revision for the page if existing.
|
||||||
*
|
|
||||||
* @return PageRevision|null
|
|
||||||
*/
|
*/
|
||||||
public function currentRevision(): HasOne
|
public function currentRevision(): HasOne
|
||||||
{
|
{
|
||||||
|
@ -87,14 +87,14 @@ class BaseRepo
|
|||||||
{
|
{
|
||||||
if ($coverImage) {
|
if ($coverImage) {
|
||||||
$imageType = $entity->coverImageTypeKey();
|
$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);
|
$image = $this->imageRepo->saveNew($coverImage, $imageType, $entity->id, 512, 512, true);
|
||||||
$entity->cover()->associate($image);
|
$entity->cover()->associate($image);
|
||||||
$entity->save();
|
$entity->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($removeImage) {
|
if ($removeImage) {
|
||||||
$this->imageRepo->destroyImage($entity->cover);
|
$this->imageRepo->destroyImage($entity->cover()->first());
|
||||||
$entity->image_id = 0;
|
$entity->image_id = 0;
|
||||||
$entity->save();
|
$entity->save();
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ class BookContents
|
|||||||
$model->changeBook($newBook->id);
|
$model->changeBook($newBook->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($chapterChanged) {
|
if ($model instanceof Page && $chapterChanged) {
|
||||||
$model->chapter_id = $newChapter->id ?? 0;
|
$model->chapter_id = $newChapter->id ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +235,7 @@ class BookContents
|
|||||||
}
|
}
|
||||||
|
|
||||||
$hasPageEditPermission = userCan('page-update', $model);
|
$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';
|
$newParentPermission = ($newParent instanceof Chapter) ? 'chapter-update' : 'book-update';
|
||||||
$hasNewParentPermission = userCan($newParentPermission, $newParent);
|
$hasNewParentPermission = userCan($newParentPermission, $newParent);
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ use BookStack\Entities\Models\Book;
|
|||||||
use BookStack\Entities\Models\Bookshelf;
|
use BookStack\Entities\Models\Bookshelf;
|
||||||
use BookStack\Entities\Models\Chapter;
|
use BookStack\Entities\Models\Chapter;
|
||||||
use BookStack\Entities\Models\Entity;
|
use BookStack\Entities\Models\Entity;
|
||||||
|
use BookStack\Entities\Models\HasCoverImage;
|
||||||
use BookStack\Entities\Models\Page;
|
use BookStack\Entities\Models\Page;
|
||||||
use BookStack\Entities\Repos\BookRepo;
|
use BookStack\Entities\Repos\BookRepo;
|
||||||
use BookStack\Entities\Repos\ChapterRepo;
|
use BookStack\Entities\Repos\ChapterRepo;
|
||||||
@ -109,9 +110,11 @@ class Cloner
|
|||||||
$inputData['tags'] = $this->entityTagsToInputArray($entity);
|
$inputData['tags'] = $this->entityTagsToInputArray($entity);
|
||||||
|
|
||||||
// Add a cover to the data if existing on the original entity
|
// Add a cover to the data if existing on the original entity
|
||||||
if ($entity->cover instanceof Image) {
|
if ($entity instanceof HasCoverImage) {
|
||||||
$uploadedFile = $this->imageToUploadedFile($entity->cover);
|
$cover = $entity->cover()->first();
|
||||||
$inputData['image'] = $uploadedFile;
|
if ($cover) {
|
||||||
|
$inputData['image'] = $this->imageToUploadedFile($cover);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $inputData;
|
return $inputData;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace BookStack\Http\Controllers;
|
namespace BookStack\Http\Controllers;
|
||||||
|
|
||||||
use BookStack\Actions\ActivityType;
|
use BookStack\Actions\ActivityType;
|
||||||
|
use BookStack\Entities\Models\PageRevision;
|
||||||
use BookStack\Entities\Repos\PageRepo;
|
use BookStack\Entities\Repos\PageRepo;
|
||||||
use BookStack\Entities\Tools\PageContent;
|
use BookStack\Entities\Tools\PageContent;
|
||||||
use BookStack\Exceptions\NotFoundException;
|
use BookStack\Exceptions\NotFoundException;
|
||||||
@ -50,6 +51,7 @@ class PageRevisionController extends Controller
|
|||||||
public function show(string $bookSlug, string $pageSlug, int $revisionId)
|
public function show(string $bookSlug, string $pageSlug, int $revisionId)
|
||||||
{
|
{
|
||||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||||
|
/** @var ?PageRevision $revision */
|
||||||
$revision = $page->revisions()->where('id', '=', $revisionId)->first();
|
$revision = $page->revisions()->where('id', '=', $revisionId)->first();
|
||||||
if ($revision === null) {
|
if ($revision === null) {
|
||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
@ -78,6 +80,7 @@ class PageRevisionController extends Controller
|
|||||||
public function changes(string $bookSlug, string $pageSlug, int $revisionId)
|
public function changes(string $bookSlug, string $pageSlug, int $revisionId)
|
||||||
{
|
{
|
||||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||||
|
/** @var ?PageRevision $revision */
|
||||||
$revision = $page->revisions()->where('id', '=', $revisionId)->first();
|
$revision = $page->revisions()->where('id', '=', $revisionId)->first();
|
||||||
if ($revision === null) {
|
if ($revision === null) {
|
||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
|
@ -19,14 +19,6 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public const HOME = '/';
|
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.
|
* Define your route model bindings, pattern filters, etc.
|
||||||
*
|
*
|
||||||
|
@ -50,7 +50,7 @@ class SearchRunner
|
|||||||
* The provided count is for each entity to search,
|
* The provided count is for each entity to search,
|
||||||
* Total returned could be larger and not guaranteed.
|
* 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
|
public function searchEntities(SearchOptions $searchOpts, string $entityType = 'all', int $page = 1, int $count = 20): array
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user