Skip to content

Commit cee23de

Browse files
committed
Maintenance: Reached PHPstan level 2
Reworked some stuff around slugs to use interface in a better way. Also standardised phpdoc to use @return instead of @returns
1 parent 1e34954 commit cee23de

34 files changed

+118
-89
lines changed

app/Access/Saml2Service.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function login(): array
5151
* Returns the SAML2 request ID, and the URL to redirect the user to.
5252
*
5353
* @throws Error
54-
* @returns array{url: string, id: ?string}
54+
* @return array{url: string, id: ?string}
5555
*/
5656
public function logout(User $user): array
5757
{

app/Access/SocialDriverManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function isAutoConfirmEmailEnabled(string $driver): bool
5555

5656
/**
5757
* Gets the names of the active social drivers, keyed by driver id.
58-
* @returns array<string, string>
58+
* @return array<string, string>
5959
*/
6060
public function getActive(): array
6161
{

app/Activity/Models/Comment.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use BookStack\App\Model;
66
use BookStack\Users\Models\HasCreatorAndUpdater;
7+
use BookStack\Users\Models\OwnableInterface;
8+
use BookStack\Users\Models\User;
79
use BookStack\Util\HtmlContentFilter;
810
use Illuminate\Database\Eloquent\Factories\HasFactory;
911
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -17,12 +19,10 @@
1719
* @property int $local_id
1820
* @property string $entity_type
1921
* @property int $entity_id
20-
* @property int $created_by
21-
* @property int $updated_by
2222
* @property string $content_ref
2323
* @property bool $archived
2424
*/
25-
class Comment extends Model implements Loggable
25+
class Comment extends Model implements Loggable, OwnableInterface
2626
{
2727
use HasFactory;
2828
use HasCreatorAndUpdater;
@@ -39,6 +39,7 @@ public function entity(): MorphTo
3939

4040
/**
4141
* Get the parent comment this is in reply to (if existing).
42+
* @return BelongsTo<Comment, Comment>
4243
*/
4344
public function parent(): BelongsTo
4445
{

app/Activity/WatchLevels.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class WatchLevels
3636

3737
/**
3838
* Get all the possible values as an option_name => value array.
39-
* @returns array<string, int>
39+
* @return array<string, int>
4040
*/
4141
public static function all(): array
4242
{
@@ -50,7 +50,7 @@ public static function all(): array
5050

5151
/**
5252
* Get the watch options suited for the given entity.
53-
* @returns array<string, int>
53+
* @return array<string, int>
5454
*/
5555
public static function allSuitedFor(Entity $entity): array
5656
{

app/App/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Model extends EloquentModel
88
{
99
/**
1010
* Provides public access to get the raw attribute value from the model.
11-
* Used in areas where no mutations are required but performance is critical.
11+
* Used in areas where no mutations are required, but performance is critical.
1212
*
1313
* @return mixed
1414
*/
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
/**
66
* Assigned to models that can have slugs.
77
* Must have the below properties.
8-
*
9-
* @property int $id
10-
* @property string $name
118
*/
12-
interface Sluggable
9+
interface SluggableInterface
1310
{
1411
/**
1512
* Regenerate the slug for this model.

app/Entities/Controllers/RecycleBinApiController.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
use BookStack\Entities\Models\BookChild;
77
use BookStack\Entities\Models\Chapter;
88
use BookStack\Entities\Models\Deletion;
9+
use BookStack\Entities\Models\Page;
910
use BookStack\Entities\Repos\DeletionRepo;
1011
use BookStack\Http\ApiController;
11-
use Closure;
12-
use Illuminate\Database\Eloquent\Builder;
12+
use Illuminate\Database\Eloquent\Relations\HasMany;
1313

1414
class RecycleBinApiController extends ApiController
1515
{
@@ -40,7 +40,7 @@ public function list()
4040
'updated_at',
4141
'deletable_type',
4242
'deletable_id',
43-
], [Closure::fromCallable([$this, 'listFormatter'])]);
43+
], [$this->listFormatter(...)]);
4444
}
4545

4646
/**
@@ -72,7 +72,6 @@ public function destroy(DeletionRepo $deletionRepo, string $deletionId)
7272
protected function listFormatter(Deletion $deletion)
7373
{
7474
$deletable = $deletion->deletable;
75-
$withTrashedQuery = fn (Builder $query) => $query->withTrashed();
7675

7776
if ($deletable instanceof BookChild) {
7877
$parent = $deletable->getParent();
@@ -81,11 +80,19 @@ protected function listFormatter(Deletion $deletion)
8180
}
8281

8382
if ($deletable instanceof Book || $deletable instanceof Chapter) {
84-
$countsToLoad = ['pages' => $withTrashedQuery];
83+
$countsToLoad = ['pages' => static::withTrashedQuery(...)];
8584
if ($deletable instanceof Book) {
86-
$countsToLoad['chapters'] = $withTrashedQuery;
85+
$countsToLoad['chapters'] = static::withTrashedQuery(...);
8786
}
8887
$deletable->loadCount($countsToLoad);
8988
}
9089
}
90+
91+
/**
92+
* @param HasMany<Chapter|Page, Book|Chapter> $query
93+
*/
94+
protected static function withTrashedQuery(HasMany $query): void
95+
{
96+
$query->withTrashed();
97+
}
9198
}

app/Entities/Models/Book.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public function sortRule(): BelongsTo
9595

9696
/**
9797
* Get all pages within this book.
98+
* @return HasMany<Page, $this>
9899
*/
99100
public function pages(): HasMany
100101
{
@@ -111,7 +112,7 @@ public function directPages(): HasMany
111112

112113
/**
113114
* Get all chapters within this book.
114-
* @return HasMany<Chapter>
115+
* @return HasMany<Chapter, $this>
115116
*/
116117
public function chapters(): HasMany
117118
{

app/Entities/Models/Bookshelf.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function getBookCover(int $width = 440, int $height = 250): string
7070

7171
/**
7272
* Get the cover image of the shelf.
73+
* @return BelongsTo<Image, $this>
7374
*/
7475
public function cover(): BelongsTo
7576
{

app/Entities/Models/Chapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Chapter extends BookChild implements HtmlDescriptionInterface
2727
/**
2828
* Get the pages that this chapter contains.
2929
*
30-
* @return HasMany<Page>
30+
* @return HasMany<Page, $this>
3131
*/
3232
public function pages(string $dir = 'ASC'): HasMany
3333
{
@@ -60,7 +60,7 @@ public function defaultTemplate(): BelongsTo
6060

6161
/**
6262
* Get the visible pages in this chapter.
63-
* @returns Collection<Page>
63+
* @return Collection<Page>
6464
*/
6565
public function getVisiblePages(): Collection
6666
{

0 commit comments

Comments
 (0)