mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-09-10 17:31:58 +03:00
phpstan: Address a range of level 2 issues
This commit is contained in:
@@ -57,16 +57,13 @@ class LdapSessionGuard extends ExternalBaseSessionGuard
|
|||||||
/**
|
/**
|
||||||
* Attempt to authenticate a user using the given credentials.
|
* Attempt to authenticate a user using the given credentials.
|
||||||
*
|
*
|
||||||
* @param array $credentials
|
|
||||||
* @param bool $remember
|
* @param bool $remember
|
||||||
*
|
*
|
||||||
* @throws LdapException*@throws \BookStack\Exceptions\JsonDebugException
|
* @throws LdapException
|
||||||
* @throws LoginAttemptException
|
* @throws LoginAttemptException
|
||||||
* @throws JsonDebugException
|
* @throws JsonDebugException
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function attempt(array $credentials = [], $remember = false)
|
public function attempt(array $credentials = [], $remember = false): bool
|
||||||
{
|
{
|
||||||
$username = $credentials['username'];
|
$username = $credentials['username'];
|
||||||
$userDetails = $this->ldapService->getUserDetails($username);
|
$userDetails = $this->ldapService->getUserDetails($username);
|
||||||
|
@@ -11,6 +11,7 @@ use BookStack\Entities\Tools\MixedEntityListLoader;
|
|||||||
use BookStack\Permissions\PermissionApplicator;
|
use BookStack\Permissions\PermissionApplicator;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
|
|
||||||
class ActivityQueries
|
class ActivityQueries
|
||||||
@@ -67,6 +68,7 @@ class ActivityQueries
|
|||||||
|
|
||||||
$activity = $query->orderBy('created_at', 'desc')
|
$activity = $query->orderBy('created_at', 'desc')
|
||||||
->with(['loggable' => function (Relation $query) {
|
->with(['loggable' => function (Relation $query) {
|
||||||
|
/** @var MorphTo<Entity, Activity> $query */
|
||||||
$query->withTrashed();
|
$query->withTrashed();
|
||||||
}, 'user.avatar'])
|
}, 'user.avatar'])
|
||||||
->skip($count * ($page - 1))
|
->skip($count * ($page - 1))
|
||||||
|
@@ -20,7 +20,8 @@ class PageUpdateNotificationHandler extends BaseNotificationHandler
|
|||||||
throw new \InvalidArgumentException("Detail for page update notifications must be a page");
|
throw new \InvalidArgumentException("Detail for page update notifications must be a page");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get last update from activity
|
// Get the last update from activity
|
||||||
|
/** @var ?Activity $lastUpdate */
|
||||||
$lastUpdate = $detail->activity()
|
$lastUpdate = $detail->activity()
|
||||||
->where('type', '=', ActivityType::PAGE_UPDATE)
|
->where('type', '=', ActivityType::PAGE_UPDATE)
|
||||||
->where('id', '!=', $activity->id)
|
->where('id', '!=', $activity->id)
|
||||||
|
@@ -50,7 +50,7 @@ class WebhookFormatter
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->detail instanceof Model) {
|
if ($this->detail instanceof Model) {
|
||||||
$data['related_item'] = $this->formatModel();
|
$data['related_item'] = $this->formatModel($this->detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
@@ -83,10 +83,8 @@ class WebhookFormatter
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function formatModel(): array
|
protected function formatModel(Model $model): array
|
||||||
{
|
{
|
||||||
/** @var Model $model */
|
|
||||||
$model = $this->detail;
|
|
||||||
$model->unsetRelations();
|
$model->unsetRelations();
|
||||||
|
|
||||||
foreach ($this->modelFormatters as $formatter) {
|
foreach ($this->modelFormatters as $formatter) {
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace BookStack\Entities\Controllers;
|
namespace BookStack\Entities\Controllers;
|
||||||
|
|
||||||
|
use BookStack\Entities\Models\Book;
|
||||||
use BookStack\Entities\Models\Chapter;
|
use BookStack\Entities\Models\Chapter;
|
||||||
use BookStack\Entities\Queries\ChapterQueries;
|
use BookStack\Entities\Queries\ChapterQueries;
|
||||||
use BookStack\Entities\Queries\EntityQueries;
|
use BookStack\Entities\Queries\EntityQueries;
|
||||||
@@ -143,7 +144,10 @@ class ChapterApiController extends ApiController
|
|||||||
$chapter->load(['tags']);
|
$chapter->load(['tags']);
|
||||||
$chapter->makeVisible('description_html');
|
$chapter->makeVisible('description_html');
|
||||||
$chapter->setAttribute('description_html', $chapter->descriptionHtml());
|
$chapter->setAttribute('description_html', $chapter->descriptionHtml());
|
||||||
$chapter->setAttribute('book_slug', $chapter->book()->first()->slug);
|
|
||||||
|
/** @var Book $book */
|
||||||
|
$book = $chapter->book()->first();
|
||||||
|
$chapter->setAttribute('book_slug', $book->slug);
|
||||||
|
|
||||||
return $chapter;
|
return $chapter;
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@ use BookStack\Users\Models\HasOwner;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
@@ -283,10 +284,14 @@ abstract class Entity extends Model implements Sluggable, Favouritable, Viewable
|
|||||||
public function getParent(): ?self
|
public function getParent(): ?self
|
||||||
{
|
{
|
||||||
if ($this instanceof Page) {
|
if ($this instanceof Page) {
|
||||||
return $this->chapter_id ? $this->chapter()->withTrashed()->first() : $this->book()->withTrashed()->first();
|
/** @var BelongsTo<Chapter|Book, Page> $builder */
|
||||||
|
$builder = $this->chapter_id ? $this->chapter() : $this->book();
|
||||||
|
return $builder->withTrashed()->first();
|
||||||
}
|
}
|
||||||
if ($this instanceof Chapter) {
|
if ($this instanceof Chapter) {
|
||||||
return $this->book()->withTrashed()->first();
|
/** @var BelongsTo<Book, Page> $builder */
|
||||||
|
$builder = $this->book();
|
||||||
|
return $builder->withTrashed()->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -295,7 +300,7 @@ abstract class Entity extends Model implements Sluggable, Favouritable, Viewable
|
|||||||
/**
|
/**
|
||||||
* Rebuild the permissions for this entity.
|
* Rebuild the permissions for this entity.
|
||||||
*/
|
*/
|
||||||
public function rebuildPermissions()
|
public function rebuildPermissions(): void
|
||||||
{
|
{
|
||||||
app()->make(JointPermissionBuilder::class)->rebuildForEntity(clone $this);
|
app()->make(JointPermissionBuilder::class)->rebuildForEntity(clone $this);
|
||||||
}
|
}
|
||||||
@@ -303,7 +308,7 @@ abstract class Entity extends Model implements Sluggable, Favouritable, Viewable
|
|||||||
/**
|
/**
|
||||||
* Index the current entity for search.
|
* Index the current entity for search.
|
||||||
*/
|
*/
|
||||||
public function indexForSearch()
|
public function indexForSearch(): void
|
||||||
{
|
{
|
||||||
app()->make(SearchIndex::class)->indexEntity(clone $this);
|
app()->make(SearchIndex::class)->indexEntity(clone $this);
|
||||||
}
|
}
|
||||||
|
@@ -134,7 +134,7 @@ class ZipExportReferences
|
|||||||
|
|
||||||
// Find and include images if in visibility
|
// Find and include images if in visibility
|
||||||
$page = $model->getPage();
|
$page = $model->getPage();
|
||||||
if ($page && userCan('view', $page)) {
|
if ($page && userCan('view', $page) && $exportModel instanceof ZipExportPage) {
|
||||||
if (!isset($this->images[$model->id])) {
|
if (!isset($this->images[$model->id])) {
|
||||||
$exportImage = ZipExportImage::fromModel($model, $files);
|
$exportImage = ZipExportImage::fromModel($model, $files);
|
||||||
$this->images[$model->id] = $exportImage;
|
$this->images[$model->id] = $exportImage;
|
||||||
|
@@ -7,6 +7,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||||||
/**
|
/**
|
||||||
* @property int $created_by
|
* @property int $created_by
|
||||||
* @property int $updated_by
|
* @property int $updated_by
|
||||||
|
* @property ?User $createdBy
|
||||||
|
* @property ?User $updatedBy
|
||||||
*/
|
*/
|
||||||
trait HasCreatorAndUpdater
|
trait HasCreatorAndUpdater
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user