mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-07-15 21:31:36 +03:00
Maintenance: Addressed all phpstan level 5 issues
This commit is contained in:
@@ -20,10 +20,10 @@ use Illuminate\Support\Collection;
|
||||
* @property ?int $image_id
|
||||
* @property ?int $default_template_id
|
||||
* @property ?int $sort_rule_id
|
||||
* @property \Illuminate\Database\Eloquent\Collection $chapters
|
||||
* @property \Illuminate\Database\Eloquent\Collection $pages
|
||||
* @property \Illuminate\Database\Eloquent\Collection $directPages
|
||||
* @property \Illuminate\Database\Eloquent\Collection $shelves
|
||||
* @property \Illuminate\Database\Eloquent\Collection<int, Chapter> $chapters
|
||||
* @property \Illuminate\Database\Eloquent\Collection<int, Page> $pages
|
||||
* @property \Illuminate\Database\Eloquent\Collection<int, Page> $directPages
|
||||
* @property \Illuminate\Database\Eloquent\Collection<int, Bookshelf> $shelves
|
||||
* @property ?SortRule $sortRule
|
||||
*/
|
||||
class Book extends Entity implements HasDescriptionInterface, HasCoverInterface, HasDefaultTemplateInterface
|
||||
|
||||
@@ -24,8 +24,8 @@ use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
* @property int $revision_count
|
||||
* @property string $editor
|
||||
* @property Chapter|null $chapter
|
||||
* @property Collection $attachments
|
||||
* @property Collection $revisions
|
||||
* @property Collection<int, Attachment> $attachments
|
||||
* @property Collection<int, PageRevision> $revisions
|
||||
* @property PageRevision $currentRevision
|
||||
*/
|
||||
class Page extends BookChild
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace BookStack\Exports;
|
||||
|
||||
use BookStack\Activity\ActivityType;
|
||||
use BookStack\Entities\Models\Book;
|
||||
use BookStack\Entities\Models\Chapter;
|
||||
use BookStack\Entities\Models\Entity;
|
||||
use BookStack\Entities\Queries\EntityQueries;
|
||||
use BookStack\Exceptions\FileUploadException;
|
||||
@@ -119,6 +121,9 @@ class ImportRepo
|
||||
$parentModel = null;
|
||||
if ($import->type === 'page' || $import->type === 'chapter') {
|
||||
$parentModel = $parent ? $this->entityQueries->findVisibleByStringIdentifier($parent) : null;
|
||||
if ($parentModel && !($parentModel instanceof Book || $parentModel instanceof Chapter)) {
|
||||
throw new ZipImportException(['Selected parent is not a book or chapter']);
|
||||
}
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
@@ -48,7 +48,7 @@ class ZipImportRunner
|
||||
* Returns the top-level entity item which was imported.
|
||||
* @throws ZipImportException
|
||||
*/
|
||||
public function run(Import $import, ?Entity $parent = null): Entity
|
||||
public function run(Import $import, Book|Chapter|null $parent = null): Entity
|
||||
{
|
||||
$zipPath = $this->getZipPath($import);
|
||||
$reader = new ZipExportReader($zipPath);
|
||||
|
||||
@@ -101,6 +101,7 @@ class JointPermissionBuilder
|
||||
|
||||
/**
|
||||
* Get a query for fetching a book with its children.
|
||||
* @return Builder<Book>
|
||||
*/
|
||||
protected function bookFetchQuery(): Builder
|
||||
{
|
||||
@@ -117,9 +118,11 @@ class JointPermissionBuilder
|
||||
|
||||
/**
|
||||
* Build joint permissions for the given book and role combinations.
|
||||
* @param EloquentCollection<int, Book> $books
|
||||
*/
|
||||
protected function buildJointPermissionsForBooks(EloquentCollection $books, array $roles, bool $deleteOld = false): void
|
||||
{
|
||||
/** @var EloquentCollection<int, Entity> $entities */
|
||||
$entities = clone $books;
|
||||
|
||||
/** @var Book $book */
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace BookStack\References;
|
||||
|
||||
use BookStack\App\Model;
|
||||
use BookStack\Permissions\Models\JointPermission;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ class ReferenceFetcher
|
||||
*/
|
||||
public function getReferencesToEntity(Entity $entity, bool $withContents = false): Collection
|
||||
{
|
||||
/** @var Collection<int, Reference> $references */
|
||||
$references = $this->queryReferencesToEntity($entity)->get();
|
||||
$this->mixedEntityListLoader->loadIntoRelations($references->all(), 'from', false, $withContents);
|
||||
|
||||
@@ -37,6 +38,9 @@ class ReferenceFetcher
|
||||
return $this->queryReferencesToEntity($entity)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder<Reference>
|
||||
*/
|
||||
protected function queryReferencesToEntity(Entity $entity): Builder
|
||||
{
|
||||
$baseQuery = Reference::query()
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace BookStack\Search;
|
||||
|
||||
use BookStack\Entities\EntityProvider;
|
||||
use BookStack\Entities\Models\Entity;
|
||||
use BookStack\Entities\Models\EntityTable;
|
||||
use BookStack\Entities\Queries\EntityQueries;
|
||||
use BookStack\Entities\Tools\EntityHydrator;
|
||||
use BookStack\Permissions\PermissionApplicator;
|
||||
@@ -90,6 +91,8 @@ class SearchRunner
|
||||
|
||||
/**
|
||||
* Get a page of result data from the given query based on the provided page parameters.
|
||||
* @param EloquentBuilder<EntityTable> $query
|
||||
* @return Collection<Entity>
|
||||
*/
|
||||
protected function getPageOfDataFromQuery(EloquentBuilder $query, int $page, int $count): Collection
|
||||
{
|
||||
@@ -106,6 +109,7 @@ class SearchRunner
|
||||
/**
|
||||
* Create a search query for an entity.
|
||||
* @param string[] $entityTypes
|
||||
* @return EloquentBuilder<EntityTable>
|
||||
*/
|
||||
protected function buildQuery(SearchOptions $searchOpts, array $entityTypes): EloquentBuilder
|
||||
{
|
||||
|
||||
@@ -243,9 +243,9 @@ class SettingService
|
||||
/**
|
||||
* Convert a setting key into a user-specific key.
|
||||
*/
|
||||
protected function userKey(string $userId, string $key = ''): string
|
||||
protected function userKey(int $userId, string $key = ''): string
|
||||
{
|
||||
return 'user:' . $userId . ':' . $key;
|
||||
return 'user:' . strval($userId) . ':' . $key;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,7 +267,7 @@ class SettingService
|
||||
/**
|
||||
* Delete settings for a given user id.
|
||||
*/
|
||||
public function deleteUserSettings(string $userId): void
|
||||
public function deleteUserSettings(int $userId): void
|
||||
{
|
||||
Setting::query()
|
||||
->where('setting_key', 'like', $this->userKey($userId) . '%')
|
||||
|
||||
@@ -38,21 +38,35 @@ class SortRule extends Model implements Loggable
|
||||
$this->sequence = implode(',', $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function logDescriptor(): string
|
||||
{
|
||||
return "({$this->id}) {$this->name}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL to where this rule can be managed.
|
||||
*/
|
||||
public function getUrl(): string
|
||||
{
|
||||
return url("/settings/sorting/rules/{$this->id}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the books which are specifically set to use this sort rule.
|
||||
* @return HasMany<Book, $this>
|
||||
*/
|
||||
public function books(): HasMany
|
||||
{
|
||||
return $this->hasMany(Book::class, 'entity_container_data.sort_rule_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the available sort rules, ordered by name, with the number of books using each.
|
||||
* @return Collection<SortRule>
|
||||
*/
|
||||
public static function allByName(): Collection
|
||||
{
|
||||
return static::query()
|
||||
|
||||
@@ -102,7 +102,7 @@ class AttachmentService
|
||||
/**
|
||||
* Updates the ordering for a listing of attached files.
|
||||
*/
|
||||
public function updateFileOrderWithinPage(array $attachmentOrder, string $pageId)
|
||||
public function updateFileOrderWithinPage(array $attachmentOrder, int $pageId)
|
||||
{
|
||||
foreach ($attachmentOrder as $index => $attachmentId) {
|
||||
Attachment::query()->where('uploaded_to', '=', $pageId)
|
||||
|
||||
@@ -87,7 +87,7 @@ class RoleApiController extends ApiController
|
||||
*/
|
||||
public function read(string $id)
|
||||
{
|
||||
$role = $this->permissionsRepo->getRoleById($id);
|
||||
$role = $this->permissionsRepo->getRoleById(intval($id));
|
||||
$this->singleFormatter($role);
|
||||
|
||||
return response()->json($role);
|
||||
|
||||
@@ -94,7 +94,7 @@ class RoleController extends Controller
|
||||
public function edit(string $id)
|
||||
{
|
||||
$this->checkPermission(Permission::UserRolesManage);
|
||||
$role = $this->permissionsRepo->getRoleById($id);
|
||||
$role = $this->permissionsRepo->getRoleById(intval($id));
|
||||
|
||||
$this->setPageTitle(trans('settings.role_edit'));
|
||||
|
||||
@@ -129,7 +129,7 @@ class RoleController extends Controller
|
||||
public function showDelete(string $id)
|
||||
{
|
||||
$this->checkPermission(Permission::UserRolesManage);
|
||||
$role = $this->permissionsRepo->getRoleById($id);
|
||||
$role = $this->permissionsRepo->getRoleById(intval($id));
|
||||
$roles = $this->permissionsRepo->getAllRolesExcept($role);
|
||||
$blankRole = $role->newInstance(['display_name' => trans('settings.role_delete_no_migration')]);
|
||||
$roles->prepend($blankRole);
|
||||
@@ -151,7 +151,7 @@ class RoleController extends Controller
|
||||
|
||||
try {
|
||||
$migrateRoleId = intval($request->input('migrate_role_id') ?: "0");
|
||||
$this->permissionsRepo->deleteRole($id, $migrateRoleId);
|
||||
$this->permissionsRepo->deleteRole(intval($id), $migrateRoleId);
|
||||
} catch (PermissionsException $e) {
|
||||
$this->showErrorNotification($e->getMessage());
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ class UserApiController extends ApiController
|
||||
*/
|
||||
public function read(string $id)
|
||||
{
|
||||
$user = $this->userRepo->getById($id);
|
||||
$user = $this->userRepo->getById(intval($id));
|
||||
$this->singleFormatter($user);
|
||||
|
||||
return response()->json($user);
|
||||
@@ -124,8 +124,8 @@ class UserApiController extends ApiController
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
$data = $this->validate($request, $this->rules($id)['update']);
|
||||
$user = $this->userRepo->getById($id);
|
||||
$data = $this->validate($request, $this->rules(intval($id))['update']);
|
||||
$user = $this->userRepo->getById(intval($id));
|
||||
$this->userRepo->update($user, $data, userCan(Permission::UsersManage));
|
||||
$this->singleFormatter($user);
|
||||
|
||||
@@ -140,7 +140,7 @@ class UserApiController extends ApiController
|
||||
*/
|
||||
public function delete(Request $request, string $id)
|
||||
{
|
||||
$user = $this->userRepo->getById($id);
|
||||
$user = $this->userRepo->getById(intval($id));
|
||||
$newOwnerId = $request->input('migrate_ownership_id', null);
|
||||
|
||||
$this->userRepo->destroy($user, $newOwnerId);
|
||||
|
||||
Reference in New Issue
Block a user