Skip to content

Commit d2542d6

Browse files
authored
Merge pull request #5491 from BookStackApp/deprecations
Addressing PHP 8.4 Deprecations
2 parents 0e343c4 + 5050719 commit d2542d6

File tree

17 files changed

+53
-40
lines changed

17 files changed

+53
-40
lines changed

app/Access/Ldap.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function setVersion($ldapConnection, int $version): bool
5454
*
5555
* @return \LDAP\Result|array|false
5656
*/
57-
public function search($ldapConnection, string $baseDn, string $filter, array $attributes = null)
57+
public function search($ldapConnection, string $baseDn, string $filter, array $attributes = [])
5858
{
5959
return ldap_search($ldapConnection, $baseDn, $filter, $attributes);
6060
}
@@ -66,7 +66,7 @@ public function search($ldapConnection, string $baseDn, string $filter, array $a
6666
*
6767
* @return \LDAP\Result|array|false
6868
*/
69-
public function read($ldapConnection, string $baseDn, string $filter, array $attributes = null)
69+
public function read($ldapConnection, string $baseDn, string $filter, array $attributes = [])
7070
{
7171
return ldap_read($ldapConnection, $baseDn, $filter, $attributes);
7272
}
@@ -87,7 +87,7 @@ public function getEntries($ldapConnection, $ldapSearchResult): array|false
8787
*
8888
* @param resource|\LDAP\Connection $ldapConnection
8989
*/
90-
public function searchAndGetEntries($ldapConnection, string $baseDn, string $filter, array $attributes = null): array|false
90+
public function searchAndGetEntries($ldapConnection, string $baseDn, string $filter, array $attributes = []): array|false
9191
{
9292
$search = $this->search($ldapConnection, $baseDn, $filter, $attributes);
9393

@@ -99,7 +99,7 @@ public function searchAndGetEntries($ldapConnection, string $baseDn, string $fil
9999
*
100100
* @param resource|\LDAP\Connection $ldapConnection
101101
*/
102-
public function bind($ldapConnection, string $bindRdn = null, string $bindPassword = null): bool
102+
public function bind($ldapConnection, ?string $bindRdn = null, ?string $bindPassword = null): bool
103103
{
104104
return ldap_bind($ldapConnection, $bindRdn, $bindPassword);
105105
}

app/Access/SocialDriverManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function addSocialDriver(
9292
string $driverName,
9393
array $config,
9494
string $socialiteHandler,
95-
callable $configureForRedirect = null
95+
?callable $configureForRedirect = null
9696
) {
9797
$this->validDrivers[] = $driverName;
9898
config()->set('services.' . $driverName, $config);

app/App/helpers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ function user(): User
4343
* Check if the current user has a permission. If an ownable element
4444
* is passed in the jointPermissions are checked against that particular item.
4545
*/
46-
function userCan(string $permission, Model $ownable = null): bool
46+
function userCan(string $permission, ?Model $ownable = null): bool
4747
{
48-
if ($ownable === null) {
48+
if (is_null($ownable)) {
4949
return user()->can($permission);
5050
}
5151

@@ -71,7 +71,7 @@ function userCanOnAny(string $action, string $entityClass = ''): bool
7171
*
7272
* @return mixed|SettingService
7373
*/
74-
function setting(string $key = null, $default = null)
74+
function setting(?string $key = null, mixed $default = null): mixed
7575
{
7676
$settingService = app()->make(SettingService::class);
7777

app/Config/exports.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
* @var array
115115
*/
116116
'allowed_protocols' => [
117+
"data://" => ["rules" => []],
117118
'file://' => ['rules' => []],
118119
'http://' => ['rules' => []],
119120
'https://' => ['rules' => []],

app/Entities/Controllers/BookController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function index(Request $request)
7070
/**
7171
* Show the form for creating a new book.
7272
*/
73-
public function create(string $shelfSlug = null)
73+
public function create(?string $shelfSlug = null)
7474
{
7575
$this->checkPermission('book-create-all');
7676

@@ -93,7 +93,7 @@ public function create(string $shelfSlug = null)
9393
* @throws ImageUploadException
9494
* @throws ValidationException
9595
*/
96-
public function store(Request $request, string $shelfSlug = null)
96+
public function store(Request $request, ?string $shelfSlug = null)
9797
{
9898
$this->checkPermission('book-create-all');
9999
$validated = $this->validate($request, [

app/Entities/Controllers/PageController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(
4141
*
4242
* @throws Throwable
4343
*/
44-
public function create(string $bookSlug, string $chapterSlug = null)
44+
public function create(string $bookSlug, ?string $chapterSlug = null)
4545
{
4646
if ($chapterSlug) {
4747
$parent = $this->entityQueries->chapters->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
@@ -69,7 +69,7 @@ public function create(string $bookSlug, string $chapterSlug = null)
6969
*
7070
* @throws ValidationException
7171
*/
72-
public function createAsGuest(Request $request, string $bookSlug, string $chapterSlug = null)
72+
public function createAsGuest(Request $request, string $bookSlug, ?string $chapterSlug = null)
7373
{
7474
$this->validate($request, [
7575
'name' => ['required', 'string', 'max:255'],

app/Entities/Queries/QueryPopular.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ public function __construct(
1818
) {
1919
}
2020

21-
public function run(int $count, int $page, array $filterModels = null): Collection
21+
public function run(int $count, int $page, array $filterModels): Collection
2222
{
2323
$query = $this->permissions
2424
->restrictEntityRelationQuery(View::query(), 'views', 'viewable_id', 'viewable_type')
2525
->select('*', 'viewable_id', 'viewable_type', DB::raw('SUM(views) as view_count'))
2626
->groupBy('viewable_id', 'viewable_type')
2727
->orderBy('view_count', 'desc');
2828

29-
if ($filterModels) {
29+
if (!empty($filterModels)) {
3030
$query->whereIn('viewable_type', $this->entityProvider->getMorphClasses($filterModels));
3131
}
3232

app/Entities/Repos/RevisionRepo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function getNewDraftForCurrentUser(Page $page): PageRevision
4646
/**
4747
* Store a new revision in the system for the given page.
4848
*/
49-
public function storeNewForPage(Page $page, string $summary = null): PageRevision
49+
public function storeNewForPage(Page $page, ?string $summary = null): PageRevision
5050
{
5151
$revision = new PageRevision();
5252

app/Theming/ThemeService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function readThemeActions(): void
9393
/**
9494
* @see SocialDriverManager::addSocialDriver
9595
*/
96-
public function addSocialDriver(string $driverName, array $config, string $socialiteHandler, callable $configureForRedirect = null): void
96+
public function addSocialDriver(string $driverName, array $config, string $socialiteHandler, ?callable $configureForRedirect = null): void
9797
{
9898
$driverManager = app()->make(SocialDriverManager::class);
9999
$driverManager->addSocialDriver($driverName, $config, $socialiteHandler, $configureForRedirect);

app/Uploads/ImageRepo.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public function getPaginatedByType(
4949
string $type,
5050
int $page = 0,
5151
int $pageSize = 24,
52-
int $uploadedTo = null,
53-
string $search = null,
54-
callable $whereClause = null
52+
?int $uploadedTo = null,
53+
?string $search = null,
54+
?callable $whereClause = null
5555
): array {
5656
$imageQuery = Image::query()->where('type', '=', strtolower($type));
5757

@@ -91,7 +91,7 @@ public function getEntityFiltered(
9191
$parentFilter = function (Builder $query) use ($filterType, $contextPage) {
9292
if ($filterType === 'page') {
9393
$query->where('uploaded_to', '=', $contextPage->id);
94-
} elseif ($filterType === 'book') {
94+
} else if ($filterType === 'book') {
9595
$validPageIds = $contextPage->book->pages()
9696
->scopes('visible')
9797
->pluck('id')
@@ -109,8 +109,14 @@ public function getEntityFiltered(
109109
*
110110
* @throws ImageUploadException
111111
*/
112-
public function saveNew(UploadedFile $uploadFile, string $type, int $uploadedTo = 0, int $resizeWidth = null, int $resizeHeight = null, bool $keepRatio = true): Image
113-
{
112+
public function saveNew(
113+
UploadedFile $uploadFile,
114+
string $type,
115+
int $uploadedTo = 0,
116+
?int $resizeWidth = null,
117+
?int $resizeHeight = null,
118+
bool $keepRatio = true
119+
): Image {
114120
$image = $this->imageService->saveNewFromUpload($uploadFile, $type, $uploadedTo, $resizeWidth, $resizeHeight, $keepRatio);
115121

116122
if ($type !== 'system') {
@@ -184,7 +190,7 @@ public function updateImageFile(Image $image, UploadedFile $file): void
184190
*
185191
* @throws Exception
186192
*/
187-
public function destroyImage(Image $image = null): void
193+
public function destroyImage(?Image $image = null): void
188194
{
189195
if ($image) {
190196
$this->imageService->destroy($image);

app/Uploads/ImageService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function saveNewFromUpload(
3131
UploadedFile $uploadedFile,
3232
string $type,
3333
int $uploadedTo = 0,
34-
int $resizeWidth = null,
35-
int $resizeHeight = null,
34+
?int $resizeWidth = null,
35+
?int $resizeHeight = null,
3636
bool $keepRatio = true,
3737
string $imageName = '',
3838
): Image {

app/Users/Controllers/UserApiController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(UserRepo $userRepo)
3333
});
3434
}
3535

36-
protected function rules(int $userId = null): array
36+
protected function rules(?int $userId = null): array
3737
{
3838
return [
3939
'create' => [
@@ -54,7 +54,7 @@ protected function rules(int $userId = null): array
5454
'string',
5555
'email',
5656
'min:2',
57-
(new Unique('users', 'email'))->ignore($userId ?? null),
57+
(new Unique('users', 'email'))->ignore($userId),
5858
],
5959
'external_auth_id' => ['string'],
6060
'language' => ['string', 'max:15', 'alpha_dash'],

app/Util/SsrUrlValidator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44

55
use BookStack\Exceptions\HttpFetchException;
66

7+
/**
8+
* Validate the host we're connecting to when making a server-side-request.
9+
* Will use the given hosts config if given during construction otherwise
10+
* will look to the app configured config.
11+
*/
712
class SsrUrlValidator
813
{
914
protected string $config;
1015

11-
public function __construct(string $config = null)
16+
public function __construct(?string $config = null)
1217
{
1318
$this->config = $config ?? config('app.ssr_hosts') ?? '';
1419
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"ext-xml": "*",
1919
"ext-zip": "*",
2020
"bacon/bacon-qr-code": "^3.0",
21-
"dompdf/dompdf": "^3.0",
21+
"dompdf/dompdf": "^3.1",
2222
"guzzlehttp/guzzle": "^7.4",
2323
"intervention/image": "^3.5",
2424
"knplabs/knp-snappy": "^1.5",

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/docs/logical-theme-system.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ This method allows you to register a custom social authentication driver within
4949
- string $driverName
5050
- array $config
5151
- string $socialiteHandler
52+
- callable|null $configureForRedirect = null
5253

5354
**Example**
5455

tests/Entity/PageEditorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,20 @@ public function test_editor_type_switch_options_show()
191191
{
192192
$resp = $this->asAdmin()->get($this->page->getUrl('/edit'));
193193
$editLink = $this->page->getUrl('/edit') . '?editor=';
194-
$this->withHtml($resp)->assertElementContains("a[href=\"${editLink}markdown-clean\"]", '(Clean Content)');
195-
$this->withHtml($resp)->assertElementContains("a[href=\"${editLink}markdown-stable\"]", '(Stable Content)');
196-
$this->withHtml($resp)->assertElementContains("a[href=\"${editLink}wysiwyg2024\"]", '(In Alpha Testing)');
194+
$this->withHtml($resp)->assertElementContains("a[href=\"{$editLink}markdown-clean\"]", '(Clean Content)');
195+
$this->withHtml($resp)->assertElementContains("a[href=\"{$editLink}markdown-stable\"]", '(Stable Content)');
196+
$this->withHtml($resp)->assertElementContains("a[href=\"{$editLink}wysiwyg2024\"]", '(In Alpha Testing)');
197197

198198
$resp = $this->asAdmin()->get($this->page->getUrl('/edit?editor=markdown-stable'));
199199
$editLink = $this->page->getUrl('/edit') . '?editor=';
200-
$this->withHtml($resp)->assertElementContains("a[href=\"${editLink}wysiwyg\"]", 'Switch to WYSIWYG Editor');
200+
$this->withHtml($resp)->assertElementContains("a[href=\"{$editLink}wysiwyg\"]", 'Switch to WYSIWYG Editor');
201201
}
202202

203203
public function test_editor_type_switch_options_dont_show_if_without_change_editor_permissions()
204204
{
205205
$resp = $this->asEditor()->get($this->page->getUrl('/edit'));
206206
$editLink = $this->page->getUrl('/edit') . '?editor=';
207-
$this->withHtml($resp)->assertElementNotExists("a[href*=\"${editLink}\"]");
207+
$this->withHtml($resp)->assertElementNotExists("a[href*=\"{$editLink}\"]");
208208
}
209209

210210
public function test_page_editor_type_switch_does_not_work_without_change_editor_permissions()

0 commit comments

Comments
 (0)