Skip to content

Commit 318b486

Browse files
committed
Maintenance: Finished changes to meet phpstan level 3
1 parent e05ec7d commit 318b486

11 files changed

Lines changed: 48 additions & 51 deletions

app/Access/Guards/AsyncExternalBaseSessionGuard.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,28 @@
33
namespace BookStack\Access\Guards;
44

55
/**
6-
* Saml2 Session Guard.
6+
* External Auth Session Guard.
77
*
8-
* The saml2 login process is async in nature meaning it does not fit very well
9-
* into the default laravel 'Guard' auth flow. Instead most of the logic is done
10-
* via the Saml2 controller & Saml2Service. This class provides a safer, thin
11-
* version of SessionGuard.
8+
* The login process for external auth (SAML2/OIDC) is async in nature, meaning it does not fit very well
9+
* into the default laravel 'Guard' auth flow. Instead, most of the logic is done via the relevant
10+
* controller and services. This class provides a safer, thin version of SessionGuard.
1211
*/
1312
class AsyncExternalBaseSessionGuard extends ExternalBaseSessionGuard
1413
{
1514
/**
1615
* Validate a user's credentials.
17-
*
18-
* @param array $credentials
19-
*
20-
* @return bool
2116
*/
22-
public function validate(array $credentials = [])
17+
public function validate(array $credentials = []): bool
2318
{
2419
return false;
2520
}
2621

2722
/**
2823
* Attempt to authenticate a user using the given credentials.
2924
*
30-
* @param array $credentials
3125
* @param bool $remember
32-
*
33-
* @return bool
3426
*/
35-
public function attempt(array $credentials = [], $remember = false)
27+
public function attempt(array $credentials = [], $remember = false): bool
3628
{
3729
return false;
3830
}

app/Access/Guards/LdapSessionGuard.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,9 @@ public function __construct(
3535
/**
3636
* Validate a user's credentials.
3737
*
38-
* @param array $credentials
39-
*
4038
* @throws LdapException
41-
*
42-
* @return bool
4339
*/
44-
public function validate(array $credentials = [])
40+
public function validate(array $credentials = []): bool
4541
{
4642
$userDetails = $this->ldapService->getUserDetails($credentials['username']);
4743

app/Access/LoginService.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,26 +95,26 @@ protected function getLastLoginAttemptDetails(): array
9595
{
9696
$value = session()->get(self::LAST_LOGIN_ATTEMPTED_SESSION_KEY);
9797
if (!$value) {
98-
return ['user_id' => null, 'method' => null];
98+
return ['user_id' => null, 'method' => null, 'remember' => false];
9999
}
100100

101101
[$id, $method, $remember, $time] = explode(':', $value);
102102
$hourAgo = time() - (60 * 60);
103103
if ($time < $hourAgo) {
104104
$this->clearLastLoginAttempted();
105105

106-
return ['user_id' => null, 'method' => null];
106+
return ['user_id' => null, 'method' => null, 'remember' => false];
107107
}
108108

109109
return ['user_id' => $id, 'method' => $method, 'remember' => boolval($remember)];
110110
}
111111

112112
/**
113-
* Set the last login attempted user.
113+
* Set the last login-attempted user.
114114
* Must be only used when credentials are correct and a login could be
115-
* achieved but a secondary factor has stopped the login.
115+
* achieved, but a secondary factor has stopped the login.
116116
*/
117-
protected function setLastLoginAttemptedForUser(User $user, string $method, bool $remember)
117+
protected function setLastLoginAttemptedForUser(User $user, string $method, bool $remember): void
118118
{
119119
session()->put(
120120
self::LAST_LOGIN_ATTEMPTED_SESSION_KEY,

app/Entities/Queries/BookQueries.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use BookStack\Exceptions\NotFoundException;
77
use Illuminate\Database\Eloquent\Builder;
88

9+
/**
10+
* @implements ProvidesEntityQueries<Book>
11+
*/
912
class BookQueries implements ProvidesEntityQueries
1013
{
1114
protected static array $listAttributes = [

app/Entities/Queries/BookshelfQueries.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use BookStack\Exceptions\NotFoundException;
77
use Illuminate\Database\Eloquent\Builder;
88

9+
/**
10+
* @implements ProvidesEntityQueries<Bookshelf>
11+
*/
912
class BookshelfQueries implements ProvidesEntityQueries
1013
{
1114
protected static array $listAttributes = [

app/Entities/Queries/ChapterQueries.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use BookStack\Exceptions\NotFoundException;
77
use Illuminate\Database\Eloquent\Builder;
88

9+
/**
10+
* @implements ProvidesEntityQueries<Chapter>
11+
*/
912
class ChapterQueries implements ProvidesEntityQueries
1013
{
1114
protected static array $listAttributes = [

app/Entities/Queries/PageQueries.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use BookStack\Exceptions\NotFoundException;
77
use Illuminate\Database\Eloquent\Builder;
88

9+
/**
10+
* @implements ProvidesEntityQueries<Page>
11+
*/
912
class PageQueries implements ProvidesEntityQueries
1013
{
1114
protected static array $contentAttributes = [
@@ -18,6 +21,9 @@ class PageQueries implements ProvidesEntityQueries
1821
'template', 'text', 'created_at', 'updated_at', 'priority', 'owned_by',
1922
];
2023

24+
/**
25+
* @return Builder<Page>
26+
*/
2127
public function start(): Builder
2228
{
2329
return Page::query();

app/Entities/Queries/ProvidesEntityQueries.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77

88
/**
99
* Interface for our classes which provide common queries for our
10-
* entity objects. Ideally all queries for entities should run through
10+
* entity objects. Ideally, all queries for entities should run through
1111
* these classes.
1212
* Any added methods should return a builder instances to allow extension
1313
* via building on the query, unless the method starts with 'find'
1414
* in which case an entity object should be returned.
1515
* (nullable unless it's a *OrFail method).
16+
*
17+
* @template TModel of Entity
1618
*/
1719
interface ProvidesEntityQueries
1820
{
1921
/**
2022
* Start a new query for this entity type.
23+
* @return Builder<TModel>
2124
*/
2225
public function start(): Builder;
2326

@@ -29,7 +32,7 @@ public function findVisibleById(int $id): ?Entity;
2932
/**
3033
* Start a query for items that are visible, with selection
3134
* configured for list display of this item.
32-
* @return Builder<Entity>
35+
* @return Builder<TModel>
3336
*/
3437
public function visibleForList(): Builder;
3538
}

app/Entities/Tools/PageIncludeParser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class PageIncludeParser
1313
protected static string $includeTagRegex = "/{{@\s?([0-9].*?)}}/";
1414

1515
/**
16-
* Elements to clean up and remove if left empty after a parsing operation.
17-
* @var DOMElement[]
16+
* Nodes to clean up and remove if left empty after a parsing operation.
17+
* @var DOMNode[]
1818
*/
1919
protected array $toCleanup = [];
2020

@@ -206,7 +206,7 @@ protected function getParentParagraph(DOMNode $parent): ?DOMNode
206206
}
207207

208208
/**
209-
* Cleanup after a parse operation.
209+
* Clean up after a parse operation.
210210
* Removes stranded elements we may have left during the parse.
211211
*/
212212
protected function cleanup(): void

app/Exceptions/Handler.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace BookStack\Exceptions;
44

5-
use Exception;
65
use Illuminate\Auth\AuthenticationException;
76
use Illuminate\Database\Eloquent\ModelNotFoundException;
87
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
@@ -12,6 +11,7 @@
1211
use Illuminate\Http\Response;
1312
use Illuminate\Validation\ValidationException;
1413
use Symfony\Component\ErrorHandler\Error\FatalError;
14+
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
1515
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
1616
use Throwable;
1717

@@ -20,7 +20,7 @@ class Handler extends ExceptionHandler
2020
/**
2121
* A list of the exception types that are not reported.
2222
*
23-
* @var array<int, class-string<\Throwable>>
23+
* @var array<int, class-string<Throwable>>
2424
*/
2525
protected $dontReport = [
2626
NotFoundException::class,
@@ -50,11 +50,11 @@ class Handler extends ExceptionHandler
5050
/**
5151
* Report or log an exception.
5252
*
53-
* @param \Throwable $exception
54-
*
55-
* @throws \Throwable
53+
* @param Throwable $exception
5654
*
5755
* @return void
56+
*@throws Throwable
57+
*
5858
*/
5959
public function report(Throwable $exception)
6060
{
@@ -64,12 +64,9 @@ public function report(Throwable $exception)
6464
/**
6565
* Render an exception into an HTTP response.
6666
*
67-
* @param \Illuminate\Http\Request $request
68-
* @param Exception $e
69-
*
70-
* @return \Illuminate\Http\Response
67+
* @param Request $request
7168
*/
72-
public function render($request, Throwable $e)
69+
public function render($request, Throwable $e): SymfonyResponse
7370
{
7471
if ($e instanceof FatalError && str_contains($e->getMessage(), 'bytes exhausted (tried to allocate') && $this->onOutOfMemory) {
7572
$response = call_user_func($this->onOutOfMemory);
@@ -152,12 +149,9 @@ protected function renderApiException(Throwable $e): JsonResponse
152149
/**
153150
* Convert an authentication exception into an unauthenticated response.
154151
*
155-
* @param \Illuminate\Http\Request $request
156-
* @param \Illuminate\Auth\AuthenticationException $exception
157-
*
158-
* @return \Illuminate\Http\Response
152+
* @param Request $request
159153
*/
160-
protected function unauthenticated($request, AuthenticationException $exception)
154+
protected function unauthenticated($request, AuthenticationException $exception): SymfonyResponse
161155
{
162156
if ($request->expectsJson()) {
163157
return response()->json(['error' => 'Unauthenticated.'], 401);
@@ -169,12 +163,9 @@ protected function unauthenticated($request, AuthenticationException $exception)
169163
/**
170164
* Convert a validation exception into a JSON response.
171165
*
172-
* @param \Illuminate\Http\Request $request
173-
* @param \Illuminate\Validation\ValidationException $exception
174-
*
175-
* @return \Illuminate\Http\JsonResponse
166+
* @param Request $request
176167
*/
177-
protected function invalidJson($request, ValidationException $exception)
168+
protected function invalidJson($request, ValidationException $exception): JsonResponse
178169
{
179170
return response()->json($exception->errors(), $exception->status);
180171
}

0 commit comments

Comments
 (0)