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);

0 commit comments

Comments
 (0)