From cd952bf08eeb873959b0ebc52f6e41e181b43371 Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Sun, 25 Aug 2024 14:59:51 +0200 Subject: [PATCH 01/12] Raise support to include PHP 8.4 --- .github/workflows/backend.yml | 2 +- bootstrap.php | 2 +- composer.json | 2 +- composer.lock | 20 ++++++++++---------- src/Cms/System.php | 2 +- tests/Cms/System/UpdateStatusTest.php | 2 +- vendor/composer/installed.json | 14 +++++++------- vendor/composer/installed.php | 6 +++--- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 42c39e4672..6b14a00362 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -57,7 +57,7 @@ jobs: timeout-minutes: 5 strategy: matrix: - php: [ "8.1", "8.2", "8.3" ] + php: ["8.1", "8.2", "8.3", "8.4"] env: extensions: mbstring, ctype, curl, gd, apcu, memcached ini: apc.enabled=1, apc.enable_cli=1, pcov.directory=., "pcov.exclude=\"~(vendor|tests)~\"" diff --git a/bootstrap.php b/bootstrap.php index 9a419de4e8..9500125f26 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -6,7 +6,7 @@ */ if ( version_compare(PHP_VERSION, '8.1.0', '>=') === false || - version_compare(PHP_VERSION, '8.4.0', '<') === false + version_compare(PHP_VERSION, '8.5.0', '<') === false ) { die(include __DIR__ . '/views/php.php'); } diff --git a/composer.json b/composer.json index 0cf0d0a7fc..73ff0d37b7 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "source": "https://github.com/getkirby/kirby" }, "require": { - "php": "~8.1.0 || ~8.2.0 || ~8.3.0", + "php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0", "ext-SimpleXML": "*", "ext-ctype": "*", "ext-curl": "*", diff --git a/composer.lock b/composer.lock index 778013c748..2e4dc4fa24 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f12b026f0a6ca67dc1bd0072f607d1eb", + "content-hash": "12243aba7a76817ee8362d62a5cad8b0", "packages": [ { "name": "christian-riesen/base32", @@ -627,16 +627,16 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v3.5.0", + "version": "v3.5.1", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1" + "reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", - "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6", + "reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6", "shasum": "" }, "require": { @@ -674,7 +674,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.0" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.1" }, "funding": [ { @@ -690,7 +690,7 @@ "type": "tidelift" } ], - "time": "2024-04-18T09:32:20+00:00" + "time": "2024-09-25T14:20:29+00:00" }, { "name": "symfony/polyfill-ctype", @@ -1091,11 +1091,11 @@ "packages-dev": [], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "~8.1.0 || ~8.2.0 || ~8.3.0", + "php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0", "ext-simplexml": "*", "ext-ctype": "*", "ext-curl": "*", @@ -1108,7 +1108,7 @@ "ext-mbstring": "*", "ext-openssl": "*" }, - "platform-dev": [], + "platform-dev": {}, "platform-overrides": { "php": "8.1.0" }, diff --git a/src/Cms/System.php b/src/Cms/System.php index f1a7ee64a7..9164a22f3e 100644 --- a/src/Cms/System.php +++ b/src/Cms/System.php @@ -364,7 +364,7 @@ public function php(): bool { return version_compare(PHP_VERSION, '8.1.0', '>=') === true && - version_compare(PHP_VERSION, '8.4.0', '<') === true; + version_compare(PHP_VERSION, '8.5.0', '<') === true; } /** diff --git a/tests/Cms/System/UpdateStatusTest.php b/tests/Cms/System/UpdateStatusTest.php index 8e9c895e05..55ca824053 100644 --- a/tests/Cms/System/UpdateStatusTest.php +++ b/tests/Cms/System/UpdateStatusTest.php @@ -72,7 +72,7 @@ public function testLoadData() '8.0' => '2023-11-26', '8.1' => '2024-11-25', '8.2' => '2025-12-08', - '8.3' => '2026-11-23' + '8.3' => '2026-11-23', ], 'incidents' => [], 'messages' => [], diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 4aa2164b65..aee7a501ad 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -651,23 +651,23 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v3.5.0", - "version_normalized": "3.5.0.0", + "version": "v3.5.1", + "version_normalized": "3.5.1.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1" + "reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", - "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6", + "reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6", "shasum": "" }, "require": { "php": ">=8.1" }, - "time": "2024-04-18T09:32:20+00:00", + "time": "2024-09-25T14:20:29+00:00", "type": "library", "extra": { "branch-alias": { @@ -701,7 +701,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.0" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.1" }, "funding": [ { diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index cba574729b..02304391ee 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -116,9 +116,9 @@ 'dev_requirement' => false, ), 'symfony/deprecation-contracts' => array( - 'pretty_version' => 'v3.5.0', - 'version' => '3.5.0.0', - 'reference' => '0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1', + 'pretty_version' => 'v3.5.1', + 'version' => '3.5.1.0', + 'reference' => '74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/deprecation-contracts', 'aliases' => array(), From 547470a5d1c26678a950bda6ddcf0aa48b64ce32 Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Thu, 21 Nov 2024 18:55:52 +0100 Subject: [PATCH 02/12] Fix Parsedown classes for PHP 8.4 --- dependencies/parsedown-extra/ParsedownExtra.php | 4 ++-- dependencies/parsedown/Parsedown.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dependencies/parsedown-extra/ParsedownExtra.php b/dependencies/parsedown-extra/ParsedownExtra.php index 2f9c62d192..390edd7ccf 100644 --- a/dependencies/parsedown-extra/ParsedownExtra.php +++ b/dependencies/parsedown-extra/ParsedownExtra.php @@ -17,7 +17,7 @@ class ParsedownExtra extends Parsedown { # ~ - public const version = '0.8.0-beta-1'; + public const version = '0.8.0-beta-2'; # ~ @@ -297,7 +297,7 @@ protected function blockMarkupComplete($Block) # # Setext - protected function blockSetextHeader($Line, array $Block = null) + protected function blockSetextHeader($Line, array|null $Block = null) { $Block = parent::blockSetextHeader($Line, $Block); diff --git a/dependencies/parsedown/Parsedown.php b/dependencies/parsedown/Parsedown.php index ab7222582c..76b2a7c205 100644 --- a/dependencies/parsedown/Parsedown.php +++ b/dependencies/parsedown/Parsedown.php @@ -17,7 +17,7 @@ class Parsedown { # ~ - public const version = '1.8.0-beta-7'; + public const version = '1.8.0-beta-8'; # ~ @@ -526,7 +526,7 @@ protected function blockHeader($Line) # # List - protected function blockList($Line, array $CurrentBlock = null) + protected function blockList($Line, array|null $CurrentBlock = null) { list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]{1,9}+[.\)]'); @@ -741,7 +741,7 @@ protected function blockRule($Line) # # Setext - protected function blockSetextHeader($Line, array $Block = null) + protected function blockSetextHeader($Line, array|null $Block = null) { if (! isset($Block) or $Block['type'] !== 'Paragraph' or isset($Block['interrupted'])) { return; @@ -821,7 +821,7 @@ protected function blockReference($Line) # # Table - protected function blockTable($Line, array $Block = null) + protected function blockTable($Line, array|null $Block = null) { if (! isset($Block) or $Block['type'] !== 'Paragraph' or isset($Block['interrupted'])) { return; From 2671d1677de41847433cc3aeef9295e78bd9d3ce Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Thu, 21 Nov 2024 19:25:02 +0100 Subject: [PATCH 03/12] Upgrade CI phpunit and psalm --- .github/workflows/backend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 6b14a00362..9e804c1f90 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -99,7 +99,7 @@ jobs: extensions: ${{ env.extensions }} ini-values: ${{ env.ini }} coverage: pcov - tools: phpunit:10.5.5, psalm:5.20.0 + tools: phpunit:11.4.3, psalm:5.26.1 - name: Setup problem matchers run: | From 9137aecc90f3b2c61726ff08f4adc8bf28213efc Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Fri, 22 Nov 2024 14:48:42 +0100 Subject: [PATCH 04/12] Upgrade simpleimage --- composer.json | 2 +- composer.lock | 14 ++++++------- .../simpleimage/src/claviska/SimpleImage.php | 20 +++++++++---------- vendor/composer/installed.json | 14 ++++++------- vendor/composer/installed.php | 6 +++--- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index 73ff0d37b7..f3342be890 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "ext-mbstring": "*", "ext-openssl": "*", "christian-riesen/base32": "1.6.0", - "claviska/simpleimage": "4.2.0", + "claviska/simpleimage": "4.2.1", "composer/semver": "3.4.3", "filp/whoops": "2.16.0", "getkirby/composer-installer": "^1.2.1", diff --git a/composer.lock b/composer.lock index 2e4dc4fa24..e71df500a9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "12243aba7a76817ee8362d62a5cad8b0", + "content-hash": "b493c4de678dcff698400049dd29b841", "packages": [ { "name": "christian-riesen/base32", @@ -67,16 +67,16 @@ }, { "name": "claviska/simpleimage", - "version": "4.2.0", + "version": "4.2.1", "source": { "type": "git", "url": "https://github.com/claviska/SimpleImage.git", - "reference": "dfbe53c01dae8467468ef2b817c09b786a7839d2" + "reference": "ec6d5021e5a7153a2520d64c59b86b6f3c4157c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/claviska/SimpleImage/zipball/dfbe53c01dae8467468ef2b817c09b786a7839d2", - "reference": "dfbe53c01dae8467468ef2b817c09b786a7839d2", + "url": "https://api.github.com/repos/claviska/SimpleImage/zipball/ec6d5021e5a7153a2520d64c59b86b6f3c4157c5", + "reference": "ec6d5021e5a7153a2520d64c59b86b6f3c4157c5", "shasum": "" }, "require": { @@ -108,7 +108,7 @@ "description": "A PHP class that makes working with images as simple as possible.", "support": { "issues": "https://github.com/claviska/SimpleImage/issues", - "source": "https://github.com/claviska/SimpleImage/tree/4.2.0" + "source": "https://github.com/claviska/SimpleImage/tree/4.2.1" }, "funding": [ { @@ -116,7 +116,7 @@ "type": "github" } ], - "time": "2024-04-15T16:07:16+00:00" + "time": "2024-11-22T13:25:03+00:00" }, { "name": "composer/semver", diff --git a/vendor/claviska/simpleimage/src/claviska/SimpleImage.php b/vendor/claviska/simpleimage/src/claviska/SimpleImage.php index c9c0c7b0bf..5c08c584c3 100644 --- a/vendor/claviska/simpleimage/src/claviska/SimpleImage.php +++ b/vendor/claviska/simpleimage/src/claviska/SimpleImage.php @@ -331,7 +331,7 @@ public function fromString(string $string): SimpleImage|static * * @throws Exception Thrown when WEBP support is not enabled or unsupported format. */ - public function generate(string $mimeType = null, array|int $options = 100): array + public function generate(string|null $mimeType = null, array|int $options = 100): array { // Format defaults to the original mime type $mimeType = $mimeType ?: $this->mimeType; @@ -473,7 +473,7 @@ public function generate(string $mimeType = null, array|int $options = 100): arr * * @throws Exception */ - public function toDataUri(string $mimeType = null, array|int $options = 100): string + public function toDataUri(string|null $mimeType = null, array|int $options = 100): string { $image = $this->generate($mimeType, $options); @@ -490,7 +490,7 @@ public function toDataUri(string $mimeType = null, array|int $options = 100): st * * @throws Exception */ - public function toDownload(string $filename, string $mimeType = null, array|int $options = 100): static + public function toDownload(string $filename, string|null $mimeType = null, array|int $options = 100): static { $image = $this->generate($mimeType, $options); @@ -517,7 +517,7 @@ public function toDownload(string $filename, string $mimeType = null, array|int * * @throws Exception Thrown if failed write to file. */ - public function toFile(string $file, string $mimeType = null, array|int $options = 100): static + public function toFile(string $file, string|null $mimeType = null, array|int $options = 100): static { $image = $this->generate($mimeType, $options); @@ -538,7 +538,7 @@ public function toFile(string $file, string $mimeType = null, array|int $options * * @throws Exception */ - public function toScreen(string $mimeType = null, array|int $options = 100): static + public function toScreen(string|null $mimeType = null, array|int $options = 100): static { $image = $this->generate($mimeType, $options); @@ -557,7 +557,7 @@ public function toScreen(string $mimeType = null, array|int $options = 100): sta * * @throws Exception */ - public function toString(string $mimeType = null, array|int $options = 100): string + public function toString(string|null $mimeType = null, array|int $options = 100): string { return $this->generate($mimeType, $options)['data']; } @@ -975,7 +975,7 @@ public function overlay(string|SimpleImage $overlay, string $anchor = 'center', * @param int|null $height The new image height. * @return SimpleImage */ - public function resize(int $width = null, int $height = null): static + public function resize(int|null $width = null, int|null $height = null): static { // No dimensions specified if (! $width && ! $height) { @@ -1027,7 +1027,7 @@ public function resize(int $width = null, int $height = null): static * @param int|null $res_y The vertical resolution in DPI * @return SimpleImage */ - public function resolution(int $res_x, int $res_y = null): static + public function resolution(int $res_x, int|null $res_y = null): static { if (is_null($res_y)) { imageresolution($this->image, $res_x); @@ -1087,7 +1087,7 @@ public function rotate(int $angle, string|array $backgroundColor = 'transparent' * * @throws Exception */ - public function text(string $text, array $options, array &$boundary = null): static + public function text(string $text, array $options, array|null &$boundary = null): static { // Check for freetype support if (! function_exists('imagettftext')) { @@ -2196,7 +2196,7 @@ public static function darkenColor(string|array $color, int $amount): array * * @throws Exception Thrown if library \League\ColorExtractor is missing. */ - public function extractColors(int $count = 5, string|array $backgroundColor = null): array + public function extractColors(int $count = 5, string|array|null $backgroundColor = null): array { // Check for required library if (! class_exists('\\'.ColorExtractor::class)) { diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index aee7a501ad..7bd8c065bc 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -64,17 +64,17 @@ }, { "name": "claviska/simpleimage", - "version": "4.2.0", - "version_normalized": "4.2.0.0", + "version": "4.2.1", + "version_normalized": "4.2.1.0", "source": { "type": "git", "url": "https://github.com/claviska/SimpleImage.git", - "reference": "dfbe53c01dae8467468ef2b817c09b786a7839d2" + "reference": "ec6d5021e5a7153a2520d64c59b86b6f3c4157c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/claviska/SimpleImage/zipball/dfbe53c01dae8467468ef2b817c09b786a7839d2", - "reference": "dfbe53c01dae8467468ef2b817c09b786a7839d2", + "url": "https://api.github.com/repos/claviska/SimpleImage/zipball/ec6d5021e5a7153a2520d64c59b86b6f3c4157c5", + "reference": "ec6d5021e5a7153a2520d64c59b86b6f3c4157c5", "shasum": "" }, "require": { @@ -86,7 +86,7 @@ "laravel/pint": "^1.5", "phpstan/phpstan": "^1.10" }, - "time": "2024-04-15T16:07:16+00:00", + "time": "2024-11-22T13:25:03+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -108,7 +108,7 @@ "description": "A PHP class that makes working with images as simple as possible.", "support": { "issues": "https://github.com/claviska/SimpleImage/issues", - "source": "https://github.com/claviska/SimpleImage/tree/4.2.0" + "source": "https://github.com/claviska/SimpleImage/tree/4.2.1" }, "funding": [ { diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 02304391ee..9a41cb4c86 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -20,9 +20,9 @@ 'dev_requirement' => false, ), 'claviska/simpleimage' => array( - 'pretty_version' => '4.2.0', - 'version' => '4.2.0.0', - 'reference' => 'dfbe53c01dae8467468ef2b817c09b786a7839d2', + 'pretty_version' => '4.2.1', + 'version' => '4.2.1.0', + 'reference' => 'ec6d5021e5a7153a2520d64c59b86b6f3c4157c5', 'type' => 'library', 'install_path' => __DIR__ . '/../claviska/simpleimage', 'aliases' => array(), From ef032a8d512aa59198bdf35f0fcf7907b52a0c4c Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Sat, 23 Nov 2024 19:06:28 +0100 Subject: [PATCH 05/12] Fix deprecated null type hinting --- .php-cs-fixer.dist.php | 3 + config/areas/site/searches.php | 4 +- config/areas/users/searches.php | 2 +- config/components.php | 10 ++-- config/fields/checkboxes.php | 4 +- config/fields/date.php | 6 +- config/fields/info.php | 2 +- config/fields/mixins/datetime.php | 2 +- config/fields/mixins/picker.php | 10 ++-- config/fields/mixins/upload.php | 2 +- config/fields/number.php | 4 +- config/fields/pages.php | 2 +- config/fields/select.php | 2 +- config/fields/slug.php | 4 +- config/fields/structure.php | 14 ++--- config/fields/tags.php | 6 +- config/fields/text.php | 8 +-- config/fields/textarea.php | 12 ++-- config/fields/time.php | 4 +- config/fields/writer.php | 4 +- config/methods.php | 4 +- config/routes.php | 4 +- config/sections/files.php | 2 +- config/sections/info.php | 4 +- config/sections/mixins/layout.php | 2 +- config/sections/mixins/max.php | 2 +- config/sections/mixins/min.php | 2 +- config/sections/mixins/pagination.php | 2 +- config/sections/mixins/parent.php | 2 +- config/sections/mixins/sort.php | 2 +- config/sections/pages.php | 2 +- src/Api/Api.php | 2 +- src/Cms/App.php | 34 +++++------ src/Cms/AppPlugins.php | 12 ++-- src/Cms/AppTranslations.php | 2 +- src/Cms/AppUsers.php | 4 +- src/Cms/Auth.php | 12 ++-- src/Cms/Blocks.php | 2 +- src/Cms/Blueprint.php | 6 +- src/Cms/Collection.php | 4 +- src/Cms/ContentLocks.php | 2 +- src/Cms/Email.php | 6 +- src/Cms/Fieldsets.php | 2 +- src/Cms/File.php | 8 +-- src/Cms/FileActions.php | 8 +-- src/Cms/FileModifications.php | 8 +-- src/Cms/FileRules.php | 4 +- src/Cms/Files.php | 8 +-- src/Cms/Find.php | 2 +- src/Cms/HasChildren.php | 4 +- src/Cms/HasFiles.php | 6 +- src/Cms/Html.php | 2 +- src/Cms/Ingredients.php | 2 +- src/Cms/Items.php | 4 +- src/Cms/Language.php | 4 +- src/Cms/Layouts.php | 2 +- src/Cms/Media.php | 2 +- src/Cms/Model.php | 4 +- src/Cms/ModelWithContent.php | 36 +++++------ src/Cms/NestCollection.php | 2 +- src/Cms/Page.php | 14 ++--- src/Cms/PageActions.php | 4 +- src/Cms/PagePicker.php | 10 ++-- src/Cms/PageRules.php | 4 +- src/Cms/Pages.php | 14 ++--- src/Cms/Pagination.php | 2 +- src/Cms/Picker.php | 2 +- src/Cms/Plugin.php | 2 +- src/Cms/Responder.php | 12 ++-- src/Cms/Roles.php | 2 +- src/Cms/Search.php | 6 +- src/Cms/Structure.php | 2 +- src/Cms/System.php | 2 +- src/Cms/Translation.php | 2 +- src/Cms/Url.php | 6 +- src/Cms/User.php | 10 ++-- src/Cms/UserActions.php | 8 +-- src/Cms/Users.php | 8 +-- src/Content/Content.php | 6 +- src/Content/ContentTranslation.php | 2 +- src/Content/Field.php | 2 +- src/Data/Txt.php | 2 +- src/Database/Query.php | 10 ++-- src/Database/Sql.php | 2 +- src/Filesystem/Dir.php | 4 +- src/Filesystem/File.php | 4 +- src/Filesystem/Mime.php | 4 +- src/Form/Field.php | 8 +-- src/Form/Field/BlocksField.php | 4 +- src/Form/Field/LayoutField.php | 2 +- src/Form/FieldClass.php | 4 +- src/Form/Fields.php | 2 +- src/Form/Mixin/Max.php | 2 +- src/Form/Mixin/Min.php | 2 +- src/Http/Environment.php | 8 +-- src/Http/Route.php | 2 +- src/Http/Url.php | 2 +- src/Option/Option.php | 2 +- src/Panel/Panel.php | 2 +- src/Panel/View.php | 6 +- src/Parsley/Parsley.php | 2 +- src/Query/Expression.php | 2 +- src/Query/Query.php | 6 +- src/Query/Segments.php | 2 +- src/Session/Session.php | 4 +- src/Session/Sessions.php | 2 +- src/Toolkit/A.php | 4 +- src/Toolkit/Collection.php | 18 +++--- src/Toolkit/Facade.php | 2 +- src/Toolkit/Html.php | 2 +- src/Toolkit/I18n.php | 12 ++-- src/Toolkit/Properties.php | 2 +- src/Toolkit/Silo.php | 4 +- src/Toolkit/Str.php | 60 +++++++++---------- src/Toolkit/V.php | 12 ++-- src/Toolkit/Xml.php | 2 +- src/Uuid/Uri.php | 2 +- tests/Cache/mocks.php | 4 +- tests/Cms/App/AppComponentsTest.php | 2 +- tests/Cms/Files/FileTest.php | 2 +- tests/Cms/Sections/mixins/LayoutMixinTest.php | 4 +- tests/Cms/Sections/mixins/SortMixinTest.php | 4 +- tests/Cms/TestCase.php | 2 +- .../Fields/Mixins/FilePickerMixinTest.php | 4 +- tests/Form/Fields/TestCase.php | 2 +- tests/Http/mocks.php | 2 +- tests/Image/DarkroomTest.php | 2 +- tests/Panel/Areas/AreaTestCase.php | 4 +- tests/Panel/Areas/PluginSearchesTest.php | 2 +- tests/Toolkit/DomTest.php | 4 +- 130 files changed, 349 insertions(+), 346 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 5dc5e7ac6e..4af6c9371e 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -43,7 +43,10 @@ 'no_unneeded_control_parentheses' => true, 'no_unused_imports' => true, 'no_useless_return' => true, + 'nullable_type_declaration' => ['syntax' => 'union'], + 'nullable_type_declaration_for_default_null_value' => true, 'ordered_imports' => ['sort_algorithm' => 'alpha'], + 'ordered_types' => ['sort_algorithm' => 'none', 'null_adjustment' => 'always_last'], // 'phpdoc_add_missing_param_annotation' => ['only_untyped' => false], // adds params in the wrong order 'phpdoc_align' => ['align' => 'left'], 'phpdoc_indent' => true, diff --git a/config/areas/site/searches.php b/config/areas/site/searches.php index 4cefefe5ff..c686936459 100644 --- a/config/areas/site/searches.php +++ b/config/areas/site/searches.php @@ -8,7 +8,7 @@ 'pages' => [ 'label' => I18n::translate('pages'), 'icon' => 'page', - 'query' => function (string $query = null, int $limit, int $page) { + 'query' => function (string|null $query = null, int $limit, int $page) { $kirby = App::instance(); $pages = $kirby->site() ->index(true) @@ -31,7 +31,7 @@ 'files' => [ 'label' => I18n::translate('files'), 'icon' => 'image', - 'query' => function (string $query = null, int $limit, int $page) { + 'query' => function (string|null $query = null, int $limit, int $page) { $kirby = App::instance(); $files = $kirby->site() ->index(true) diff --git a/config/areas/users/searches.php b/config/areas/users/searches.php index 82bce90b3a..6ad3a1fe85 100644 --- a/config/areas/users/searches.php +++ b/config/areas/users/searches.php @@ -8,7 +8,7 @@ 'users' => [ 'label' => I18n::translate('users'), 'icon' => 'users', - 'query' => function (string $query = null, int $limit, int $page) { + 'query' => function (string|null $query = null, int $limit, int $page) { $kirby = App::instance(); $users = $kirby->users() ->search($query) diff --git a/config/components.php b/config/components.php index 637e96f1f8..ab93814f31 100644 --- a/config/components.php +++ b/config/components.php @@ -118,7 +118,7 @@ */ 'markdown' => function ( App $kirby, - string $text = null, + string|null $text = null, array $options = [] ): string { static $markdown; @@ -230,7 +230,7 @@ $scoring['score'] += 16 * $score; $scoring['hits'] += 1; - // check for exact beginning matches + // check for exact beginning matches } elseif ( $options['words'] === false && Str::startsWith($lowerValue, $query) === true @@ -238,7 +238,7 @@ $scoring['score'] += 8 * $score; $scoring['hits'] += 1; - // check for exact query matches + // check for exact query matches } elseif ($matches = preg_match_all('!' . $exact . '!ui', $value, $r)) { $scoring['score'] += 2 * $score; $scoring['hits'] += $matches; @@ -270,7 +270,7 @@ */ 'smartypants' => function ( App $kirby, - string $text = null, + string|null $text = null, array $options = [] ): string { static $smartypants; @@ -354,7 +354,7 @@ */ 'url' => function ( App $kirby, - string $path = null, + string|null $path = null, $options = null ): string { $language = null; diff --git a/config/fields/checkboxes.php b/config/fields/checkboxes.php index c8d962dc99..00a94b83dc 100644 --- a/config/fields/checkboxes.php +++ b/config/fields/checkboxes.php @@ -29,13 +29,13 @@ /** * Maximum number of checked boxes */ - 'max' => function (int $max = null) { + 'max' => function (int|null $max = null) { return $max; }, /** * Minimum number of checked boxes */ - 'min' => function (int $min = null) { + 'min' => function (int|null $min = null) { return $min; }, 'value' => function ($value = null) { diff --git a/config/fields/date.php b/config/fields/date.php index 1cfa41cd86..34559db040 100644 --- a/config/fields/date.php +++ b/config/fields/date.php @@ -24,7 +24,7 @@ /** * Default date when a new page/file/user gets created */ - 'default' => function (string $default = null): string { + 'default' => function (string|null $default = null): string { return $this->toDatetime($default) ?? ''; }, @@ -46,13 +46,13 @@ /** * Latest date, which can be selected/saved (Y-m-d) */ - 'max' => function (string $max = null): string|null { + 'max' => function (string|null $max = null): string|null { return Date::optional($max); }, /** * Earliest date, which can be selected/saved (Y-m-d) */ - 'min' => function (string $min = null): string|null { + 'min' => function (string|null $min = null): string|null { return Date::optional($min); }, diff --git a/config/fields/info.php b/config/fields/info.php index e65dc83065..57907a2b24 100644 --- a/config/fields/info.php +++ b/config/fields/info.php @@ -26,7 +26,7 @@ /** * Change the design of the info box */ - 'theme' => function (string $theme = null) { + 'theme' => function (string|null $theme = null) { return $theme; } ], diff --git a/config/fields/mixins/datetime.php b/config/fields/mixins/datetime.php index b47a865d0c..8d43d2a9ad 100644 --- a/config/fields/mixins/datetime.php +++ b/config/fields/mixins/datetime.php @@ -7,7 +7,7 @@ /** * Defines a custom format that is used when the field is saved */ - 'format' => function (string $format = null) { + 'format' => function (string|null $format = null) { return $format; } ], diff --git a/config/fields/mixins/picker.php b/config/fields/mixins/picker.php index a555c2f8a4..0e4c5b88de 100644 --- a/config/fields/mixins/picker.php +++ b/config/fields/mixins/picker.php @@ -23,7 +23,7 @@ /** * Info text for each item */ - 'info' => function (string $info = null) { + 'info' => function (string|null $info = null) { return $info; }, @@ -37,14 +37,14 @@ /** * The minimum number of required selected */ - 'min' => function (int $min = null) { + 'min' => function (int|null $min = null) { return $min; }, /** * The maximum number of allowed selected */ - 'max' => function (int $max = null) { + 'max' => function (int|null $max = null) { return $max; }, @@ -58,7 +58,7 @@ /** * Query for the items to be included in the picker */ - 'query' => function (string $query = null) { + 'query' => function (string|null $query = null) { return $query; }, @@ -86,7 +86,7 @@ /** * Main text for each item */ - 'text' => function (string $text = null) { + 'text' => function (string|null $text = null) { return $text; }, ], diff --git a/config/fields/mixins/upload.php b/config/fields/mixins/upload.php index a5b9962675..ec136bd909 100644 --- a/config/fields/mixins/upload.php +++ b/config/fields/mixins/upload.php @@ -74,7 +74,7 @@ return $map($file, $parent); }); }, - 'uploadParent' => function (string $parentQuery = null) { + 'uploadParent' => function (string|null $parentQuery = null) { $parent = $this->model(); if ($parentQuery) { diff --git a/config/fields/number.php b/config/fields/number.php index 11334e878a..cc418879c8 100644 --- a/config/fields/number.php +++ b/config/fields/number.php @@ -13,13 +13,13 @@ /** * The lowest allowed number */ - 'min' => function (float $min = null) { + 'min' => function (float|null $min = null) { return $min; }, /** * The highest allowed number */ - 'max' => function (float $max = null) { + 'max' => function (float|null $max = null) { return $max; }, /** diff --git a/config/fields/pages.php b/config/fields/pages.php index 54d9aa8e9a..3d9d56d7e6 100644 --- a/config/fields/pages.php +++ b/config/fields/pages.php @@ -31,7 +31,7 @@ /** * Optional query to select a specific set of pages */ - 'query' => function (string $query = null) { + 'query' => function (string|null $query = null) { return $query; }, diff --git a/config/fields/select.php b/config/fields/select.php index 4c06b5b971..2f09c2d78c 100644 --- a/config/fields/select.php +++ b/config/fields/select.php @@ -13,7 +13,7 @@ /** * Custom icon to replace the arrow down. */ - 'icon' => function (string $icon = null) { + 'icon' => function (string|null $icon = null) { return $icon; }, /** diff --git a/config/fields/slug.php b/config/fields/slug.php index 9d8efb552f..15c6839cf2 100644 --- a/config/fields/slug.php +++ b/config/fields/slug.php @@ -28,7 +28,7 @@ /** * Set prefix for the help text */ - 'path' => function (string $path = null) { + 'path' => function (string|null $path = null) { return $path; }, @@ -36,7 +36,7 @@ * Name of another field that should be used to * automatically update this field's value */ - 'sync' => function (string $sync = null) { + 'sync' => function (string|null $sync = null) { return $sync; }, diff --git a/config/fields/structure.php b/config/fields/structure.php index 510459b8b4..66b614c386 100644 --- a/config/fields/structure.php +++ b/config/fields/structure.php @@ -45,7 +45,7 @@ /** * Set the default rows for the structure */ - 'default' => function (array $default = null) { + 'default' => function (array|null $default = null) { return $default; }, @@ -58,38 +58,38 @@ /** * The number of entries that will be displayed on a single page. Afterwards pagination kicks in. */ - 'limit' => function (int $limit = null) { + 'limit' => function (int|null $limit = null) { return $limit; }, /** * Maximum allowed entries in the structure. Afterwards the "Add" button will be switched off. */ - 'max' => function (int $max = null) { + 'max' => function (int|null $max = null) { return $max; }, /** * Minimum required entries in the structure */ - 'min' => function (int $min = null) { + 'min' => function (int|null $min = null) { return $min; }, /** * Toggles adding to the top or bottom of the list */ - 'prepend' => function (bool $prepend = null) { + 'prepend' => function (bool|null $prepend = null) { return $prepend; }, /** * Toggles drag & drop sorting */ - 'sortable' => function (bool $sortable = null) { + 'sortable' => function (bool|null $sortable = null) { return $sortable; }, /** * Sorts the entries by the given field and order (i.e. `title desc`) * Drag & drop is disabled in this case */ - 'sortBy' => function (string $sort = null) { + 'sortBy' => function (string|null $sort = null) { return $sort; } ], diff --git a/config/fields/tags.php b/config/fields/tags.php index b5b6c9ec99..90020bc668 100644 --- a/config/fields/tags.php +++ b/config/fields/tags.php @@ -37,13 +37,13 @@ /** * Minimum number of required entries/tags */ - 'min' => function (int $min = null) { + 'min' => function (int|null $min = null) { return $min; }, /** * Maximum number of allowed entries/tags */ - 'max' => function (int $max = null) { + 'max' => function (int|null $max = null) { return $max; }, /** @@ -93,7 +93,7 @@ return $value; } ], - 'save' => function (array $value = null): string { + 'save' => function (array|null $value = null): string { return A::join( $value, $this->separator() . ' ' diff --git a/config/fields/text.php b/config/fields/text.php index 574a4ecb0c..ac87d854c2 100644 --- a/config/fields/text.php +++ b/config/fields/text.php @@ -30,28 +30,28 @@ /** * Sets the font family (sans or monospace) */ - 'font' => function (string $font = null) { + 'font' => function (string|null $font = null) { return $font === 'monospace' ? 'monospace' : 'sans-serif'; }, /** * Maximum number of allowed characters */ - 'maxlength' => function (int $maxlength = null) { + 'maxlength' => function (int|null $maxlength = null) { return $maxlength; }, /** * Minimum number of required characters */ - 'minlength' => function (int $minlength = null) { + 'minlength' => function (int|null $minlength = null) { return $minlength; }, /** * A regular expression, which will be used to validate the input */ - 'pattern' => function (string $pattern = null) { + 'pattern' => function (string|null $pattern = null) { return $pattern; }, diff --git a/config/fields/textarea.php b/config/fields/textarea.php index 7b51c1f5ef..e09d6c1d84 100644 --- a/config/fields/textarea.php +++ b/config/fields/textarea.php @@ -26,7 +26,7 @@ /** * Sets the default text when a new page/file/user is created */ - 'default' => function (string $default = null) { + 'default' => function (string|null $default = null) { return trim($default ?? ''); }, @@ -48,28 +48,28 @@ /** * Sets the font family (sans or monospace) */ - 'font' => function (string $font = null) { + 'font' => function (string|null $font = null) { return $font === 'monospace' ? 'monospace' : 'sans-serif'; }, /** * Maximum number of allowed characters */ - 'maxlength' => function (int $maxlength = null) { + 'maxlength' => function (int|null $maxlength = null) { return $maxlength; }, /** * Minimum number of required characters */ - 'minlength' => function (int $minlength = null) { + 'minlength' => function (int|null $minlength = null) { return $minlength; }, /** * Changes the size of the textarea. Available sizes: `small`, `medium`, `large`, `huge` */ - 'size' => function (string $size = null) { + 'size' => function (string|null $size = null) { return $size; }, @@ -80,7 +80,7 @@ return $spellcheck; }, - 'value' => function (string $value = null) { + 'value' => function (string|null $value = null) { return trim($value ?? ''); } ], diff --git a/config/fields/time.php b/config/fields/time.php index 4a0b6fc699..413420bbf4 100644 --- a/config/fields/time.php +++ b/config/fields/time.php @@ -36,13 +36,13 @@ /** * Latest time, which can be selected/saved (H:i or H:i:s) */ - 'max' => function (string $max = null): string|null { + 'max' => function (string|null $max = null): string|null { return Date::optional($max); }, /** * Earliest time, which can be selected/saved (H:i or H:i:s) */ - 'min' => function (string $min = null): string|null { + 'min' => function (string|null $min = null): string|null { return Date::optional($min); }, diff --git a/config/fields/writer.php b/config/fields/writer.php index c9f7869f89..72440fff36 100644 --- a/config/fields/writer.php +++ b/config/fields/writer.php @@ -36,14 +36,14 @@ /** * Maximum number of allowed characters */ - 'maxlength' => function (int $maxlength = null) { + 'maxlength' => function (int|null $maxlength = null) { return $maxlength; }, /** * Minimum number of required characters */ - 'minlength' => function (int $minlength = null) { + 'minlength' => function (int|null $minlength = null) { return $minlength; }, /** diff --git a/config/methods.php b/config/methods.php index 870c243217..760ab24f4d 100644 --- a/config/methods.php +++ b/config/methods.php @@ -115,7 +115,7 @@ 'toDate' => function ( Field $field, string|IntlDateFormatter|null $format = null, - string $fallback = null + string|null $fallback = null ) use ($app): string|int|null { if (empty($field->value) === true && $fallback === null) { return null; @@ -504,7 +504,7 @@ */ 'query' => function ( Field $field, - string $expect = null + string|null $expect = null ) use ($app): mixed { if ($parent = $field->parent()) { return $parent->query($field->value, $expect); diff --git a/config/routes.php b/config/routes.php index cd7924da36..0699ef1328 100644 --- a/config/routes.php +++ b/config/routes.php @@ -33,7 +33,7 @@ 'pattern' => $api . '/(:all)', 'method' => 'ALL', 'env' => 'api', - 'action' => function (string $path = null) use ($kirby) { + 'action' => function (string|null $path = null) use ($kirby) { if ($kirby->option('api') === false) { return null; } @@ -125,7 +125,7 @@ 'pattern' => $panel . '/(:all?)', 'method' => 'ALL', 'env' => 'panel', - 'action' => function (string $path = null) { + 'action' => function (string|null $path = null) { return Panel::router($path); } ], diff --git a/config/sections/files.php b/config/sections/files.php index 35ff9e3eb9..8bab322c82 100644 --- a/config/sections/files.php +++ b/config/sections/files.php @@ -28,7 +28,7 @@ /** * Filters all files by template and also sets the template, which will be used for all uploads */ - 'template' => function (string $template = null) { + 'template' => function (string|null $template = null) { return $template; }, /** diff --git a/config/sections/info.php b/config/sections/info.php index 7999aac542..20a288d5c6 100644 --- a/config/sections/info.php +++ b/config/sections/info.php @@ -7,13 +7,13 @@ 'headline', ], 'props' => [ - 'icon' => function (string $icon = null) { + 'icon' => function (string|null $icon = null) { return $icon; }, 'text' => function ($text = null) { return I18n::translate($text, $text); }, - 'theme' => function (string $theme = null) { + 'theme' => function (string|null $theme = null) { return $theme; } ], diff --git a/config/sections/mixins/layout.php b/config/sections/mixins/layout.php index 75230b0d4e..b3481763b6 100644 --- a/config/sections/mixins/layout.php +++ b/config/sections/mixins/layout.php @@ -10,7 +10,7 @@ /** * Columns config for `layout: table` */ - 'columns' => function (array $columns = null) { + 'columns' => function (array|null $columns = null) { return $columns ?? []; }, /** diff --git a/config/sections/mixins/max.php b/config/sections/mixins/max.php index a87c1cc317..b49c627e98 100644 --- a/config/sections/mixins/max.php +++ b/config/sections/mixins/max.php @@ -5,7 +5,7 @@ /** * Sets the maximum number of allowed entries in the section */ - 'max' => function (int $max = null) { + 'max' => function (int|null $max = null) { return $max; } ], diff --git a/config/sections/mixins/min.php b/config/sections/mixins/min.php index 6295f2d506..40fa82ed28 100644 --- a/config/sections/mixins/min.php +++ b/config/sections/mixins/min.php @@ -5,7 +5,7 @@ /** * Sets the minimum number of required entries in the section */ - 'min' => function (int $min = null) { + 'min' => function (int|null $min = null) { return $min; } ], diff --git a/config/sections/mixins/pagination.php b/config/sections/mixins/pagination.php index 3b2a2b0f62..ba3cdf5508 100644 --- a/config/sections/mixins/pagination.php +++ b/config/sections/mixins/pagination.php @@ -14,7 +14,7 @@ /** * Sets the default page for the pagination. This will overwrite default pagination. */ - 'page' => function (int $page = null) { + 'page' => function (int|null $page = null) { return App::instance()->request()->get('page', $page); }, ], diff --git a/config/sections/mixins/parent.php b/config/sections/mixins/parent.php index 1096930e39..1217411068 100644 --- a/config/sections/mixins/parent.php +++ b/config/sections/mixins/parent.php @@ -11,7 +11,7 @@ /** * Sets the query to a parent to find items for the list */ - 'parent' => function (string $parent = null) { + 'parent' => function (string|null $parent = null) { return $parent; } ], diff --git a/config/sections/mixins/sort.php b/config/sections/mixins/sort.php index 5b994ec71b..118e03b3c3 100644 --- a/config/sections/mixins/sort.php +++ b/config/sections/mixins/sort.php @@ -17,7 +17,7 @@ /** * Overwrites manual sorting and sorts by the given field and sorting direction (i.e. `date desc`) */ - 'sortBy' => function (string $sortBy = null) { + 'sortBy' => function (string|null $sortBy = null) { return $sortBy; }, ], diff --git a/config/sections/pages.php b/config/sections/pages.php index 7f142aefda..6ca10909f1 100644 --- a/config/sections/pages.php +++ b/config/sections/pages.php @@ -53,7 +53,7 @@ /** * Filters the list by single template. */ - 'template' => function (string|array $template = null) { + 'template' => function (string|array|null $template = null) { return $template; }, /** diff --git a/src/Api/Api.php b/src/Api/Api.php index 75b5d1d6f0..e7647b3921 100644 --- a/src/Api/Api.php +++ b/src/Api/Api.php @@ -592,7 +592,7 @@ protected function setRequestData( * @return $this */ protected function setRequestMethod( - string $requestMethod = null + string|null $requestMethod = null ): static { $this->requestMethod = $requestMethod ?? 'GET'; return $this; diff --git a/src/Cms/App.php b/src/Cms/App.php index 32044c7406..953d22d98e 100644 --- a/src/Cms/App.php +++ b/src/Cms/App.php @@ -285,7 +285,7 @@ protected function bakeOptions(): static * * @return $this */ - protected function bakeRoots(array $roots = null): static + protected function bakeRoots(array|null $roots = null): static { $roots = array_merge($this->core->roots(), (array)$roots); $this->roots = Ingredients::bake($roots); @@ -297,7 +297,7 @@ protected function bakeRoots(array $roots = null): static * * @return $this */ - protected function bakeUrls(array $urls = null): static + protected function bakeUrls(array|null $urls = null): static { $urls = array_merge($this->core->urls(), (array)$urls); $this->urls = Ingredients::bake($urls); @@ -331,7 +331,7 @@ public function blueprints(string $type = 'pages'): array /** * Calls any Kirby route */ - public function call(string $path = null, string $method = null): mixed + public function call(string|null $path = null, string|null $method = null): mixed { $path ??= $this->path(); $method ??= $this->request()->method(); @@ -697,7 +697,7 @@ public function image(string|null $path = null): File|null * @psalm-return ($lazy is false ? static : static|null) */ public static function instance( - self $instance = null, + self|null $instance = null, bool $lazy = false ): static|null { if ($instance !== null) { @@ -852,7 +852,7 @@ public function kirbytag( * * @internal */ - public function kirbytags(string $text = null, array $data = []): string + public function kirbytags(string|null $text = null, array $data = []): string { $data['kirby'] ??= $this; $data['site'] ??= $data['kirby']->site(); @@ -872,7 +872,7 @@ public function kirbytags(string $text = null, array $data = []): string * * @internal */ - public function kirbytext(string $text = null, array $options = []): string + public function kirbytext(string|null $text = null, array $options = []): string { $text = $this->apply('kirbytext:before', compact('text'), 'text'); $text = $this->kirbytags($text, $options); @@ -891,7 +891,7 @@ public function kirbytext(string $text = null, array $options = []): string * Returns the language by code or shortcut (`default`, `current`). * Passing `null` is an alias for passing `current` */ - public function language(string $code = null): Language|null + public function language(string|null $code = null): Language|null { if ($this->multilang() === false) { return null; @@ -909,7 +909,7 @@ public function language(string $code = null): Language|null * * @internal */ - public function languageCode(string $languageCode = null): string|null + public function languageCode(string|null $languageCode = null): string|null { return $this->language($languageCode)?->code(); } @@ -952,7 +952,7 @@ public function locks(): ContentLocks * * @internal */ - public function markdown(string $text = null, array $options = null): string + public function markdown(string|null $text = null, array|null $options = null): string { // merge global options with local options $options = array_merge( @@ -1181,8 +1181,8 @@ public function path(): string * current request */ public function render( - string $path = null, - string $method = null + string|null $path = null, + string|null $method = null ): Response|null { if (($_ENV['KIRBY_RENDER'] ?? true) === false) { return null; @@ -1441,7 +1441,7 @@ public function setCurrentLanguage( * * @return $this */ - protected function setLanguages(array $languages = null): static + protected function setLanguages(array|null $languages = null): static { if ($languages !== null) { $objects = []; @@ -1462,7 +1462,7 @@ protected function setLanguages(array $languages = null): static * * @return $this */ - protected function setPath(string $path = null): static + protected function setPath(string|null $path = null): static { $this->path = $path !== null ? trim($path, '/') : null; return $this; @@ -1473,7 +1473,7 @@ protected function setPath(string $path = null): static * * @return $this */ - protected function setRequest(array $request = null): static + protected function setRequest(array|null $request = null): static { if ($request !== null) { $this->request = new Request($request); @@ -1487,7 +1487,7 @@ protected function setRequest(array $request = null): static * * @return $this */ - protected function setRoles(array $roles = null): static + protected function setRoles(array|null $roles = null): static { if ($roles !== null) { $this->roles = Roles::factory($roles); @@ -1501,7 +1501,7 @@ protected function setRoles(array $roles = null): static * * @return $this */ - protected function setSite(Site|array $site = null): static + protected function setSite(Site|array|null $site = null): static { if (is_array($site) === true) { $site = new Site($site); @@ -1528,7 +1528,7 @@ public function site(): Site * * @internal */ - public function smartypants(string $text = null): string + public function smartypants(string|null $text = null): string { $options = $this->option('smartypants', []); diff --git a/src/Cms/AppPlugins.php b/src/Cms/AppPlugins.php index 8cfeae3d62..645c6525dd 100644 --- a/src/Cms/AppPlugins.php +++ b/src/Cms/AppPlugins.php @@ -99,7 +99,7 @@ trait AppPlugins */ public function extend( array $extensions, - Plugin $plugin = null + Plugin|null $plugin = null ): array { foreach ($this->extensions as $type => $registered) { if (isset($extensions[$type]) === true) { @@ -382,7 +382,7 @@ protected function extendLayoutsMethods(array $methods): array */ protected function extendOptions( array $options, - Plugin $plugin = null + Plugin|null $plugin = null ): array { if ($plugin !== null) { $options = [$plugin->prefix() => $options]; @@ -428,7 +428,7 @@ protected function extendPages(array $pages): array */ protected function extendPermissions( array $permissions, - Plugin $plugin = null + Plugin|null $plugin = null ): array { if ($plugin !== null) { $permissions = [$plugin->prefix() => $permissions]; @@ -583,7 +583,7 @@ public function extension( * * @internal */ - public function extensions(string $type = null): array + public function extensions(string|null $type = null): array { if ($type === null) { return $this->extensions; @@ -713,7 +713,7 @@ public function nativeComponent(string $component): Closure|false */ public static function plugin( string $name, - array $extends = null, + array|null $extends = null, array $info = [], string|null $root = null, string|null $version = null @@ -747,7 +747,7 @@ public static function plugin( * @internal * @param array|null $plugins Can be used to overwrite the plugins registry */ - public function plugins(array $plugins = null): array + public function plugins(array|null $plugins = null): array { // overwrite the existing plugins registry if ($plugins !== null) { diff --git a/src/Cms/AppTranslations.php b/src/Cms/AppTranslations.php index 1efae287cb..1e24f23700 100644 --- a/src/Cms/AppTranslations.php +++ b/src/Cms/AppTranslations.php @@ -108,7 +108,7 @@ public function panelLanguage(): string * * @internal */ - public function setCurrentTranslation(string $translationCode = null): void + public function setCurrentTranslation(string|null $translationCode = null): void { I18n::$locale = $translationCode ?? 'en'; } diff --git a/src/Cms/AppUsers.php b/src/Cms/AppUsers.php index 82a61f08ad..6f2f7be524 100644 --- a/src/Cms/AppUsers.php +++ b/src/Cms/AppUsers.php @@ -72,7 +72,7 @@ public function impersonate( * * @return $this */ - protected function setUser(User|string $user = null): static + protected function setUser(User|string|null $user = null): static { $this->user = $user; return $this; @@ -83,7 +83,7 @@ protected function setUser(User|string $user = null): static * * @return $this */ - protected function setUsers(array $users = null): static + protected function setUsers(array|null $users = null): static { if ($users !== null) { $this->users = Users::factory($users); diff --git a/src/Cms/Auth.php b/src/Cms/Auth.php index d02b01e158..689f5677a2 100644 --- a/src/Cms/Auth.php +++ b/src/Cms/Auth.php @@ -202,7 +202,7 @@ public function csrfFromSession(): string * @throws \Kirby\Exception\InvalidArgumentException if the authorization header is invalid * @throws \Kirby\Exception\PermissionException if basic authentication is not allowed */ - public function currentUserFromBasicAuth(BasicAuth $auth = null): User|null + public function currentUserFromBasicAuth(BasicAuth|null $auth = null): User|null { if ($this->kirby->option('api.basicAuth', false) !== true) { throw new PermissionException('Basic authentication is not activated'); @@ -250,7 +250,7 @@ public function currentUserFromImpersonation(): User|null * valid user id in there */ public function currentUserFromSession( - Session|array $session = null + Session|array|null $session = null ): User|null { $session = $this->session($session); @@ -440,7 +440,7 @@ public function setUser(User $user): void * logged in user will be returned */ public function status( - Session|array $session = null, + Session|array|null $session = null, bool $allowImpersonation = true ): Status { // try to return from cache @@ -723,7 +723,7 @@ public function type(bool $allowImpersonation = true): string * @throws \Throwable If an authentication error occurred */ public function user( - Session|array $session = null, + Session|array|null $session = null, bool $allowImpersonation = true ): User|null { if ($allowImpersonation === true && $this->impersonate !== null) { @@ -887,7 +887,7 @@ class_exists(static::$challenges[$challenge]) === true && */ protected function fail( Throwable $exception, - Throwable $fallback = null + Throwable|null $fallback = null ): void { $debug = $this->kirby->option('auth.debug', 'log'); @@ -911,7 +911,7 @@ protected function fail( /** * Creates a session object from the passed options */ - protected function session(Session|array $session = null): Session + protected function session(Session|array|null $session = null): Session { // use passed session options or session object if set if (is_array($session) === true) { diff --git a/src/Cms/Blocks.php b/src/Cms/Blocks.php index 6ea7a6cd41..5e0c0c963e 100644 --- a/src/Cms/Blocks.php +++ b/src/Cms/Blocks.php @@ -54,7 +54,7 @@ public function excerpt(mixed ...$args): string * catch blocks from layouts */ public static function factory( - array $items = null, + array|null $items = null, array $params = [] ): static { $items = static::extractFromLayouts($items); diff --git a/src/Cms/Blueprint.php b/src/Cms/Blueprint.php index 7895c851c6..e9c7dd2d84 100644 --- a/src/Cms/Blueprint.php +++ b/src/Cms/Blueprint.php @@ -39,7 +39,7 @@ class Blueprint /** * Magic getter/caller for any blueprint prop */ - public function __call(string $key, array $arguments = null): mixed + public function __call(string $key, array|null $arguments = null): mixed { return $this->props[$key] ?? null; } @@ -102,7 +102,7 @@ public function __debugInfo(): array * Gathers what file templates are allowed in * this model based on the blueprint */ - public function acceptedFileTemplates(string $inSection = null): array + public function acceptedFileTemplates(string|null $inSection = null): array { // get cached results for the current file model // (except when collecting for a specific section) @@ -320,7 +320,7 @@ public static function extend($props): array */ public static function factory( string $name, - string $fallback = null, + string|null $fallback = null, ModelWithContent $model ): static|null { try { diff --git a/src/Cms/Collection.php b/src/Cms/Collection.php index a4a5cb65b8..251b2285ca 100644 --- a/src/Cms/Collection.php +++ b/src/Cms/Collection.php @@ -365,7 +365,7 @@ public function remove($key) * Searches the collection */ public function search( - string $query = null, + string|null $query = null, string|array $params = [] ): static { return Search::collection($this, $query, $params); @@ -376,7 +376,7 @@ public function search( * to an array. This can also take a callback * function to further modify the array result. */ - public function toArray(Closure $map = null): array + public function toArray(Closure|null $map = null): array { return parent::toArray($map ?? fn ($object) => $object->toArray()); } diff --git a/src/Cms/ContentLocks.php b/src/Cms/ContentLocks.php index 2d7c400102..bdcc6f4927 100644 --- a/src/Cms/ContentLocks.php +++ b/src/Cms/ContentLocks.php @@ -173,7 +173,7 @@ public function set(ModelWithContent $model, array $data): bool ) { unset($this->data[$file][$id]); - // there is empty unlock data, but still lock data + // there is empty unlock data, but still lock data } elseif ( isset($data['unlock']) === true && count($data['unlock']) === 0 diff --git a/src/Cms/Email.php b/src/Cms/Email.php index 80900dc91e..18f06a2976 100644 --- a/src/Cms/Email.php +++ b/src/Cms/Email.php @@ -113,7 +113,7 @@ protected function template(): void $this->props['body']['text'] = $text->render($data); } - // fallback to single email text template + // fallback to single email text template } elseif ($text->exists()) { $this->props['body'] = $text->render($data); } else { @@ -125,7 +125,7 @@ protected function template(): void /** * Returns an email template by name and type */ - protected function getTemplate(string $name, string $type = null): Template + protected function getTemplate(string $name, string|null $type = null): Template { return App::instance()->template('emails/' . $name, $type, 'text'); } @@ -163,7 +163,7 @@ protected function transformModel( string $prop, string $class, string $contentValue, - string $contentKey = null + string|null $contentKey = null ): array { $value = $this->props[$prop] ?? []; diff --git a/src/Cms/Fieldsets.php b/src/Cms/Fieldsets.php index 181f1c448d..4f5f5ceec2 100644 --- a/src/Cms/Fieldsets.php +++ b/src/Cms/Fieldsets.php @@ -74,7 +74,7 @@ protected static function createFieldsets(array $params): array } public static function factory( - array $items = null, + array|null $items = null, array $params = [] ): static { $items ??= App::instance()->option('blocks.fieldsets', [ diff --git a/src/Cms/File.php b/src/Cms/File.php index 9937bdc642..a3d47ea9ed 100644 --- a/src/Cms/File.php +++ b/src/Cms/File.php @@ -155,7 +155,7 @@ public function blueprint(): FileBlueprint * Returns an array with all blueprints that are available for the file * by comparing files sections and files fields of the parent model */ - public function blueprints(string $inSection = null): array + public function blueprints(string|null $inSection = null): array { // get cached results for the current file model // (except when collecting for a specific section) @@ -227,7 +227,7 @@ public function blueprints(string $inSection = null): array */ public function contentFileData( array $data, - string $languageCode = null + string|null $languageCode = null ): array { // only add the template in, if the $data array // doesn't explicitly unsets it @@ -443,7 +443,7 @@ public function modified( * Timestamp of the last modification * of the content file */ - protected function modifiedContent(string $languageCode = null): int + protected function modifiedContent(string|null $languageCode = null): int { return $this->storage()->modified('published', $languageCode) ?? 0; } @@ -548,7 +548,7 @@ protected function rules(): FileRules * * @return $this */ - protected function setBlueprint(array $blueprint = null): static + protected function setBlueprint(array|null $blueprint = null): static { if ($blueprint !== null) { $blueprint['model'] = $this; diff --git a/src/Cms/FileActions.php b/src/Cms/FileActions.php index 712291a6df..54fbdca435 100644 --- a/src/Cms/FileActions.php +++ b/src/Cms/FileActions.php @@ -404,8 +404,8 @@ public function replace(string $source, bool $move = false): static * @internal */ public function save( - array $data = null, - string $languageCode = null, + array|null $data = null, + string|null $languageCode = null, bool $overwrite = false ): static { $file = parent::save($data, $languageCode, $overwrite); @@ -444,8 +444,8 @@ public function unpublish(bool $onlyMedia = false): static * @throws \Kirby\Exception\InvalidArgumentException If the input array contains invalid values */ public function update( - array $input = null, - string $languageCode = null, + array|null $input = null, + string|null $languageCode = null, bool $validate = false ): static { // delete all public media versions when focus field gets changed diff --git a/src/Cms/FileModifications.php b/src/Cms/FileModifications.php index d1a256d62b..38629ab8ff 100644 --- a/src/Cms/FileModifications.php +++ b/src/Cms/FileModifications.php @@ -38,7 +38,7 @@ public function bw(): FileVersion|File|Asset */ public function crop( int $width, - int $height = null, + int|null $height = null, $options = null ): FileVersion|File|Asset { $quality = null; @@ -94,9 +94,9 @@ public function quality(int $quality): FileVersion|File|Asset * @throws \Kirby\Exception\InvalidArgumentException */ public function resize( - int $width = null, - int $height = null, - int $quality = null + int|null $width = null, + int|null $height = null, + int|null $quality = null ): FileVersion|File|Asset { return $this->thumb([ 'width' => $width, diff --git a/src/Cms/FileRules.php b/src/Cms/FileRules.php index 84a93ec2a4..ee4b9dd831 100644 --- a/src/Cms/FileRules.php +++ b/src/Cms/FileRules.php @@ -252,7 +252,7 @@ public static function validExtension(File $file, string $extension): bool * Validates the extension, MIME type and filename * * @param $mime If not passed, the MIME type is detected from the file, - * if `false`, the MIME type is not validated for performance reasons + * if `false`, the MIME type is not validated for performance reasons * @throws \Kirby\Exception\InvalidArgumentException If the extension, MIME type or filename is missing or forbidden */ public static function validFile( @@ -312,7 +312,7 @@ public static function validFilename(File $file, string $filename): bool * * @throws \Kirby\Exception\InvalidArgumentException If the MIME type is missing or forbidden */ - public static function validMime(File $file, string $mime = null): bool + public static function validMime(File $file, string|null $mime = null): bool { // make it easier to compare the mime $mime = strtolower($mime ?? ''); diff --git a/src/Cms/Files.php b/src/Cms/Files.php index 70760b27df..ed5c76af55 100644 --- a/src/Cms/Files.php +++ b/src/Cms/Files.php @@ -44,19 +44,19 @@ public function add($object): static if ($object instanceof self) { $this->data = array_merge($this->data, $object->data); - // add a file by id + // add a file by id } elseif ( is_string($object) === true && $file = App::instance()->file($object) ) { $this->__set($file->id(), $file); - // add a file object + // add a file object } elseif ($object instanceof File) { $this->__set($object->id(), $object); - // give a useful error message on invalid input; - // silently ignore "empty" values for compatibility with existing setups + // give a useful error message on invalid input; + // silently ignore "empty" values for compatibility with existing setups } elseif (in_array($object, [null, false, true], true) !== true) { throw new InvalidArgumentException('You must pass a Files or File object or an ID of an existing file to the Files collection'); } diff --git a/src/Cms/Find.php b/src/Cms/Find.php index aa2c363824..6059c81e32 100644 --- a/src/Cms/Find.php +++ b/src/Cms/Find.php @@ -142,7 +142,7 @@ public static function parent(string $path): ModelWithContent * @param string|null $id User's id * @throws \Kirby\Exception\NotFoundException if the user for the given id cannot be found */ - public static function user(string $id = null): User|null + public static function user(string|null $id = null): User|null { // account is a reserved word to find the current // user. It's used in various API and area routes. diff --git a/src/Cms/HasChildren.php b/src/Cms/HasChildren.php index 4bc88da2da..d12ee38c7d 100644 --- a/src/Cms/HasChildren.php +++ b/src/Cms/HasChildren.php @@ -176,7 +176,7 @@ public function index(bool $drafts = false): Pages * * @return $this */ - protected function setChildren(array $children = null): static + protected function setChildren(array|null $children = null): static { if ($children !== null) { $this->children = Pages::factory($children, $this); @@ -190,7 +190,7 @@ protected function setChildren(array $children = null): static * * @return $this */ - protected function setDrafts(array $drafts = null): static + protected function setDrafts(array|null $drafts = null): static { if ($drafts !== null) { $this->drafts = Pages::factory($drafts, $this, true); diff --git a/src/Cms/HasFiles.php b/src/Cms/HasFiles.php index 86788d28e5..cc6ac65ca5 100644 --- a/src/Cms/HasFiles.php +++ b/src/Cms/HasFiles.php @@ -63,7 +63,7 @@ public function documents(): Files * Returns a specific file by filename or the first one */ public function file( - string $filename = null, + string|null $filename = null, string $in = 'files' ): File|null { if ($filename === null) { @@ -152,7 +152,7 @@ public function hasVideos(): bool /** * Returns a specific image by filename or the first one */ - public function image(string $filename = null): File|null + public function image(string|null $filename = null): File|null { return $this->file($filename, 'images'); } @@ -170,7 +170,7 @@ public function images(): Files * * @return $this */ - protected function setFiles(array $files = null): static + protected function setFiles(array|null $files = null): static { if ($files !== null) { $this->files = Files::factory($files, $this); diff --git a/src/Cms/Html.php b/src/Cms/Html.php index 9ab61c4c0c..dfe81014c5 100644 --- a/src/Cms/Html.php +++ b/src/Cms/Html.php @@ -81,7 +81,7 @@ public static function css( */ public static function link( string|null $href = null, - string|array $text = null, + string|array|null $text = null, array $attr = [] ): string { return parent::link(Url::to($href), $text, $attr); diff --git a/src/Cms/Ingredients.php b/src/Cms/Ingredients.php index f9c1c59e54..e8f4b330bb 100644 --- a/src/Cms/Ingredients.php +++ b/src/Cms/Ingredients.php @@ -34,7 +34,7 @@ public function __construct(array $ingredients) /** * Magic getter for single ingredients */ - public function __call(string $method, array $args = null): mixed + public function __call(string $method, array|null $args = null): mixed { return $this->ingredients[$method] ?? null; } diff --git a/src/Cms/Items.php b/src/Cms/Items.php index 97f8104590..13cc9664bb 100644 --- a/src/Cms/Items.php +++ b/src/Cms/Items.php @@ -48,7 +48,7 @@ public function __construct($objects = [], array $options = []) * an array of item props */ public static function factory( - array $items = null, + array|null $items = null, array $params = [] ): static { if (empty($items) === true || is_array($items) === false) { @@ -93,7 +93,7 @@ public function field(): Field|null /** * Convert the items to an array */ - public function toArray(Closure $map = null): array + public function toArray(Closure|null $map = null): array { return array_values(parent::toArray($map)); } diff --git a/src/Cms/Language.php b/src/Cms/Language.php index d9e3ebac24..4c6b491784 100644 --- a/src/Cms/Language.php +++ b/src/Cms/Language.php @@ -344,7 +344,7 @@ public static function loadRules(string $code): array * * @param int $category If passed, returns the locale for the specified category (e.g. LC_ALL) as string */ - public function locale(int $category = null): array|string|null + public function locale(int|null $category = null): array|string|null { if ($category !== null) { return $this->locale[$category] ?? $this->locale[LC_ALL] ?? null; @@ -513,7 +513,7 @@ public function url(): string * Update language properties and save them * @internal */ - public function update(array $props = null): static + public function update(array|null $props = null): static { $kirby = App::instance(); $user = $kirby->user(); diff --git a/src/Cms/Layouts.php b/src/Cms/Layouts.php index 188868000c..fa6031ca78 100644 --- a/src/Cms/Layouts.php +++ b/src/Cms/Layouts.php @@ -26,7 +26,7 @@ class Layouts extends Items public static array $methods = []; public static function factory( - array $items = null, + array|null $items = null, array $params = [] ): static { // convert single layout to layouts array diff --git a/src/Cms/Media.php b/src/Cms/Media.php index 45c801704f..d210c8bbb3 100644 --- a/src/Cms/Media.php +++ b/src/Cms/Media.php @@ -27,7 +27,7 @@ class Media * and to copy it to the media folder. */ public static function link( - Page|Site|User $model = null, + Page|Site|User|null $model = null, string $hash, string $filename ): Response|false { diff --git a/src/Cms/Model.php b/src/Cms/Model.php index b7010d38a7..a9c61e582d 100644 --- a/src/Cms/Model.php +++ b/src/Cms/Model.php @@ -86,7 +86,7 @@ public function site() * @param \Kirby\Cms\App|null $kirby * @return $this */ - protected function setKirby(App $kirby = null) + protected function setKirby(App|null $kirby = null) { static::$kirby = $kirby; return $this; @@ -99,7 +99,7 @@ protected function setKirby(App $kirby = null) * @param \Kirby\Cms\Site|null $site * @return $this */ - public function setSite(Site $site = null) + public function setSite(Site|null $site = null) { $this->site = $site; return $this; diff --git a/src/Cms/ModelWithContent.php b/src/Cms/ModelWithContent.php index 1a7baf5011..d5253071a5 100644 --- a/src/Cms/ModelWithContent.php +++ b/src/Cms/ModelWithContent.php @@ -71,7 +71,7 @@ abstract public function blueprint(): Blueprint; /** * Returns an array with all blueprints that are available */ - public function blueprints(string $inSection = null): array + public function blueprints(string|null $inSection = null): array { // helper function $toBlueprints = function (array $sections): array { @@ -176,7 +176,7 @@ public function content(string|null $languageCode = null): Content * @throws \Kirby\Exception\InvalidArgumentException If the language for the given code does not exist */ public function contentFile( - string $languageCode = null, + string|null $languageCode = null, bool $force = false ): string { Helpers::deprecated('The internal $model->contentFile() method has been deprecated. You can use $model->storage()->contentFile() instead, however please note that this method is also internal and may be removed in the future.', 'model-content-file'); @@ -212,7 +212,7 @@ public function contentFiles(): array */ public function contentFileData( array $data, - string $languageCode = null + string|null $languageCode = null ): array { return $data; } @@ -371,7 +371,7 @@ public function id(): string|null public function increment( string $field, int $by = 1, - int $max = null + int|null $max = null ): static { $value = (int)$this->content()->get($field)->value() + $by; @@ -462,8 +462,8 @@ public function purge(): static * @internal */ public function query( - string $query = null, - string $expect = null + string|null $query = null, + string|null $expect = null ): mixed { if ($query === null) { return null; @@ -491,7 +491,7 @@ public function query( * Read the content from the content file * @internal */ - public function readContent(string $languageCode = null): array + public function readContent(string|null $languageCode = null): array { try { return $this->storage()->read( @@ -531,7 +531,7 @@ public function save( * Save the single language content */ protected function saveContent( - array $data = null, + array|null $data = null, bool $overwrite = false ): static { // create a clone to avoid modifying the original @@ -552,8 +552,8 @@ protected function saveContent( * @throws \Kirby\Exception\InvalidArgumentException If the language for the given code does not exist */ protected function saveTranslation( - array $data = null, - string $languageCode = null, + array|null $data = null, + string|null $languageCode = null, bool $overwrite = false ): static { // create a clone to not touch the original @@ -603,7 +603,7 @@ protected function saveTranslation( * * @return $this */ - protected function setContent(array $content = null): static + protected function setContent(array|null $content = null): static { if ($content !== null) { $content = new Content($content, $this); @@ -618,7 +618,7 @@ protected function setContent(array $content = null): static * * @return $this */ - protected function setTranslations(array $translations = null): static + protected function setTranslations(array|null $translations = null): static { if ($translations !== null) { $this->translations = new Collection(); @@ -675,7 +675,7 @@ public function toArray(): array * (`null` to keep the original token) */ public function toSafeString( - string $template = null, + string|null $template = null, array $data = [], string|null $fallback = '' ): string { @@ -691,7 +691,7 @@ public function toSafeString( * @param string $handler For internal use */ public function toString( - string $template = null, + string|null $template = null, array $data = [], string|null $fallback = '', string $handler = 'template' @@ -728,7 +728,7 @@ public function __toString(): string * If no code is specified the current translation is returned */ public function translation( - string $languageCode = null + string|null $languageCode = null ): ContentTranslation|null { if ($language = $this->kirby()->language($languageCode)) { return $this->translations()->find($language->code()); @@ -766,8 +766,8 @@ public function translations(): Collection * @throws \Kirby\Exception\InvalidArgumentException If the input array contains invalid values */ public function update( - array $input = null, - string $languageCode = null, + array|null $input = null, + string|null $languageCode = null, bool $validate = false ): static { $form = Form::for($this, [ @@ -811,7 +811,7 @@ public function uuid(): Uuid|null * to store the given data on disk or anywhere else * @internal */ - public function writeContent(array $data, string $languageCode = null): bool + public function writeContent(array $data, string|null $languageCode = null): bool { $data = $this->contentFileData($data, $languageCode); $id = $this->storage()->defaultVersion(); diff --git a/src/Cms/NestCollection.php b/src/Cms/NestCollection.php index 129668dc75..605b0cb0ae 100644 --- a/src/Cms/NestCollection.php +++ b/src/Cms/NestCollection.php @@ -21,7 +21,7 @@ class NestCollection extends BaseCollection * to an array. This can also take a callback * function to further modify the array result. */ - public function toArray(Closure $map = null): array + public function toArray(Closure|null $map = null): array { return parent::toArray($map ?? fn ($object) => $object->toArray()); } diff --git a/src/Cms/Page.php b/src/Cms/Page.php index 413a267396..a1e04df3dd 100644 --- a/src/Cms/Page.php +++ b/src/Cms/Page.php @@ -776,7 +776,7 @@ public function isUnlisted(): bool * This is only used for drafts so far. * @internal */ - public function isVerified(string $token = null): bool + public function isVerified(string|null $token = null): bool { if ( $this->isPublished() === true && @@ -1091,7 +1091,7 @@ public function search(string|null $query = null, string|array $params = []): Pa * * @return $this */ - protected function setBlueprint(array $blueprint = null): static + protected function setBlueprint(array|null $blueprint = null): static { if ($blueprint !== null) { $blueprint['model'] = $this; @@ -1106,7 +1106,7 @@ protected function setBlueprint(array $blueprint = null): static * * @return $this */ - protected function setTemplate(string $template = null): static + protected function setTemplate(string|null $template = null): static { if ($template !== null) { $this->intendedTemplate = $this->kirby()->template($template); @@ -1120,7 +1120,7 @@ protected function setTemplate(string $template = null): static * * @return $this */ - protected function setUrl(string $url = null): static + protected function setUrl(string|null $url = null): static { if (is_string($url) === true) { $url = rtrim($url, '/'); @@ -1133,7 +1133,7 @@ protected function setUrl(string $url = null): static /** * Returns the slug of the page */ - public function slug(string $languageCode = null): string + public function slug(string|null $languageCode = null): string { if ($this->kirby()->multilang() === true) { $languageCode ??= $this->kirby()->languageCode(); @@ -1245,7 +1245,7 @@ public function uid(): string * The uri is the same as the id, except * that it will be translated in multi-language setups */ - public function uri(string $languageCode = null): string + public function uri(string|null $languageCode = null): string { // set the id, depending on the parent if ($parent = $this->parent()) { @@ -1301,7 +1301,7 @@ public function url($options = null): string */ public function urlForLanguage( $language = null, - array $options = null + array|null $options = null ): string { if ($options !== null) { return Url::to($this->urlForLanguage($language), $options); diff --git a/src/Cms/PageActions.php b/src/Cms/PageActions.php index 4145692428..4e27018288 100644 --- a/src/Cms/PageActions.php +++ b/src/Cms/PageActions.php @@ -578,7 +578,7 @@ public function createChild(array $props): Page * Create the sorting number for the page * depending on the blueprint settings */ - public function createNum(int $num = null): int + public function createNum(int|null $num = null): int { $mode = $this->blueprint()->num(); @@ -827,7 +827,7 @@ public function purge(): static /** * @throws \Kirby\Exception\LogicException If the page is not included in the siblings collection */ - protected function resortSiblingsAfterListing(int $position = null): bool + protected function resortSiblingsAfterListing(int|null $position = null): bool { // get all siblings including the current page $siblings = $this diff --git a/src/Cms/PagePicker.php b/src/Cms/PagePicker.php index f8dccf8002..e51464a1de 100644 --- a/src/Cms/PagePicker.php +++ b/src/Cms/PagePicker.php @@ -79,7 +79,7 @@ public function modelForQuery(): Page|Site|null * parent model that is currently selected * in the page picker. */ - public function modelToArray(Page|Site $model = null): array|null + public function modelToArray(Page|Site|null $model = null): array|null { if ($model === null) { return null; @@ -126,13 +126,13 @@ public function items(): Pages|null if (empty($this->options['query']) === true) { $items = $this->itemsForParent(); - // when subpage navigation is enabled, a parent - // might be passed in addition to the query. - // The parent then takes priority. + // when subpage navigation is enabled, a parent + // might be passed in addition to the query. + // The parent then takes priority. } elseif ($this->options['subpages'] === true && empty($this->options['parent']) === false) { $items = $this->itemsForParent(); - // search by query + // search by query } else { $items = $this->itemsForQuery(); } diff --git a/src/Cms/PageRules.php b/src/Cms/PageRules.php index 8bc6736dd7..bef0993ebd 100644 --- a/src/Cms/PageRules.php +++ b/src/Cms/PageRules.php @@ -25,7 +25,7 @@ class PageRules * * @throws \Kirby\Exception\InvalidArgumentException If the given number is invalid */ - public static function changeNum(Page $page, int $num = null): bool + public static function changeNum(Page $page, int|null $num = null): bool { if ($num !== null && $num < 0) { throw new InvalidArgumentException(['key' => 'page.num.invalid']); @@ -86,7 +86,7 @@ public static function changeSlug(Page $page, string $slug): bool public static function changeStatus( Page $page, string $status, - int $position = null + int|null $position = null ): bool { if (isset($page->blueprint()->status()[$status]) === false) { throw new InvalidArgumentException(['key' => 'page.status.invalid']); diff --git a/src/Cms/Pages.php b/src/Cms/Pages.php index 692d047b93..8c967089ba 100644 --- a/src/Cms/Pages.php +++ b/src/Cms/Pages.php @@ -61,19 +61,19 @@ public function add($object): static if ($object instanceof self) { $this->data = array_merge($this->data, $object->data); - // add a page by id + // add a page by id } elseif ( is_string($object) === true && $page = $site->find($object) ) { $this->__set($page->id(), $page); - // add a page object + // add a page object } elseif ($object instanceof Page) { $this->__set($object->id(), $object); - // give a useful error message on invalid input; - // silently ignore "empty" values for compatibility with existing setups + // give a useful error message on invalid input; + // silently ignore "empty" values for compatibility with existing setups } elseif (in_array($object, [null, false, true], true) !== true) { throw new InvalidArgumentException('You must pass a Pages or Page object or an ID of an existing page to the Pages collection'); } @@ -142,8 +142,8 @@ public function drafts(): Pages */ public static function factory( array $pages, - Page|Site $model = null, - bool $draft = null + Page|Site|null $model = null, + bool|null $draft = null ): static { $model ??= App::instance()->site(); $children = new static([], $model); @@ -248,7 +248,7 @@ public function findByKey(string|null $key = null): Page|null */ protected function findByKeyRecursive( string $id, - string $startAt = null, + string|null $startAt = null, bool $multiLang = false ) { $path = explode('/', $id); diff --git a/src/Cms/Pagination.php b/src/Cms/Pagination.php index fdefdddabd..223d80ab89 100644 --- a/src/Cms/Pagination.php +++ b/src/Cms/Pagination.php @@ -125,7 +125,7 @@ public function nextPageUrl(): string|null * If the `$page` variable is set, the URL * for that page will be returned. */ - public function pageUrl(int $page = null): string|null + public function pageUrl(int|null $page = null): string|null { if ($page === null) { return $this->pageUrl($this->page()); diff --git a/src/Cms/Picker.php b/src/Cms/Picker.php index da4b7a5c4b..f3bcce0bc9 100644 --- a/src/Cms/Picker.php +++ b/src/Cms/Picker.php @@ -68,7 +68,7 @@ abstract public function items(): Collection|null; * array that is already optimized for the * panel picker component. */ - public function itemsToArray(Collection $items = null): array + public function itemsToArray(Collection|null $items = null): array { if ($items === null) { return []; diff --git a/src/Cms/Plugin.php b/src/Cms/Plugin.php index d20a4c35a3..cc6cc8fc56 100644 --- a/src/Cms/Plugin.php +++ b/src/Cms/Plugin.php @@ -77,7 +77,7 @@ public function __construct( /** * Allows access to any composer.json field by method call */ - public function __call(string $key, array $arguments = null): mixed + public function __call(string $key, array|null $arguments = null): mixed { return $this->info()[$key] ?? null; } diff --git a/src/Cms/Responder.php b/src/Cms/Responder.php index e99ce565b6..640381e142 100644 --- a/src/Cms/Responder.php +++ b/src/Cms/Responder.php @@ -75,7 +75,7 @@ public function __toString(): string * * @return $this|string|null */ - public function body(string $body = null): static|string|null + public function body(string|null $body = null): static|string|null { if ($body === null) { return $this->body; @@ -210,7 +210,7 @@ public function expires($expires = null, bool $override = false) * * @return int|$this */ - public function code(int $code = null) + public function code(int|null $code = null) { if ($code === null) { return $this->code; @@ -266,7 +266,7 @@ public function header(string $key, $value = null, bool $lazy = false) * * @return array|$this */ - public function headers(array $headers = null) + public function headers(array|null $headers = null) { if ($headers === null) { $injectedHeaders = []; @@ -305,7 +305,7 @@ public function headers(array $headers = null) * * @return string|$this */ - public function json(array $json = null) + public function json(array|null $json = null) { if ($json !== null) { $this->body(json_encode($json)); @@ -334,7 +334,7 @@ public function redirect( /** * Creates and returns the response object from the config */ - public function send(string $body = null): Response + public function send(string|null $body = null): Response { if ($body !== null) { $this->body($body); @@ -365,7 +365,7 @@ public function toArray(): array * * @return string|$this */ - public function type(string $type = null) + public function type(string|null $type = null) { if ($type === null) { return $this->type; diff --git a/src/Cms/Roles.php b/src/Cms/Roles.php index b2a4decc7e..4b33db6a9f 100644 --- a/src/Cms/Roles.php +++ b/src/Cms/Roles.php @@ -96,7 +96,7 @@ public static function factory(array $roles, array $inject = []): static return $collection->sort('name', 'asc'); } - public static function load(string $root = null, array $inject = []): static + public static function load(string|null $root = null, array $inject = []): static { $kirby = App::instance(); $roles = new static(); diff --git a/src/Cms/Search.php b/src/Cms/Search.php index 14add5ccbe..b8e66f9ecf 100644 --- a/src/Cms/Search.php +++ b/src/Cms/Search.php @@ -17,7 +17,7 @@ class Search { public static function files( - string $query = null, + string|null $query = null, array $params = [] ): Files { return App::instance()->site()->index()->files()->search($query, $params); @@ -36,14 +36,14 @@ public static function collection( } public static function pages( - string $query = null, + string|null $query = null, array $params = [] ): Pages { return App::instance()->site()->index()->search($query, $params); } public static function users( - string $query = null, + string|null $query = null, array $params = [] ): Users { return App::instance()->users()->search($query, $params); diff --git a/src/Cms/Structure.php b/src/Cms/Structure.php index 222881dab7..efdfad1133 100644 --- a/src/Cms/Structure.php +++ b/src/Cms/Structure.php @@ -30,7 +30,7 @@ class Structure extends Items * an array of item props */ public static function factory( - array $items = null, + array|null $items = null, array $params = [] ): static { if (is_array($items) === true) { diff --git a/src/Cms/System.php b/src/Cms/System.php index 9164a22f3e..8e55161e1c 100644 --- a/src/Cms/System.php +++ b/src/Cms/System.php @@ -385,7 +385,7 @@ public function plugins(): Collection * @throws \Kirby\Exception\Exception * @throws \Kirby\Exception\InvalidArgumentException */ - public function register(string $license = null, string $email = null): bool + public function register(string|null $license = null, string|null $email = null): bool { $license = new License( code: $license, diff --git a/src/Cms/Translation.php b/src/Cms/Translation.php index 680f212ef3..d71d336689 100644 --- a/src/Cms/Translation.php +++ b/src/Cms/Translation.php @@ -87,7 +87,7 @@ public function direction(): string * Returns a single translation * string by key */ - public function get(string $key, string $default = null): string|null + public function get(string $key, string|null $default = null): string|null { return $this->data[$key] ?? $default; } diff --git a/src/Cms/Url.php b/src/Cms/Url.php index 2ec0fd72a6..eb5036f436 100644 --- a/src/Cms/Url.php +++ b/src/Cms/Url.php @@ -44,9 +44,9 @@ public static function home(): string * @return string The safe string */ public static function slug( - string $string = null, - string $separator = null, - string $allowed = null, + string|null $string = null, + string|null $separator = null, + string|null $allowed = null, ): string { $maxlength = App::instance()->option('slugs.maxlength', 255); return Str::slug($string, $separator, $allowed, $maxlength); diff --git a/src/Cms/User.php b/src/Cms/User.php index d72df942d7..6b09900a2c 100644 --- a/src/Cms/User.php +++ b/src/Cms/User.php @@ -239,7 +239,7 @@ public static function factory(mixed $props): static */ public static function hashPassword( #[SensitiveParameter] - string $password = null + string|null $password = null ): string|null { if ($password !== null) { $password = password_hash($password, PASSWORD_DEFAULT); @@ -279,7 +279,7 @@ public function inventory(): array /** * Compares the current object with the given user object */ - public function is(User $user = null): bool + public function is(User|null $user = null): bool { if ($user === null) { return false; @@ -625,7 +625,7 @@ public function secret(string $key): mixed * * @return $this */ - protected function setBlueprint(array $blueprint = null): static + protected function setBlueprint(array|null $blueprint = null): static { if ($blueprint !== null) { $blueprint['model'] = $this; @@ -683,7 +683,7 @@ public function toArray(): array * (`null` to keep the original token) */ public function toString( - string $template = null, + string|null $template = null, array $data = [], string|null $fallback = '', string $handler = 'template' @@ -711,7 +711,7 @@ public function username(): string|null */ public function validatePassword( #[SensitiveParameter] - string $password = null + string|null $password = null ): bool { if (empty($this->password()) === true) { throw new NotFoundException(['key' => 'user.password.undefined']); diff --git a/src/Cms/UserActions.php b/src/Cms/UserActions.php index 728acc1c55..3f0ccac5fb 100644 --- a/src/Cms/UserActions.php +++ b/src/Cms/UserActions.php @@ -209,7 +209,7 @@ protected function commit( /** * Creates a new User from the given props and returns a new User object */ - public static function create(array $props = null): User + public static function create(array|null $props = null): User { $data = $props; @@ -364,8 +364,8 @@ protected function readSecrets(): array * Updates the user data */ public function update( - array $input = null, - string $languageCode = null, + array|null $input = null, + string|null $languageCode = null, bool $validate = false ): static { $user = parent::update($input, $languageCode, $validate); @@ -408,7 +408,7 @@ protected function writeCredentials(array $credentials): bool */ protected function writePassword( #[SensitiveParameter] - string $password = null + string|null $password = null ): bool { return $this->writeSecret('password', $password); } diff --git a/src/Cms/Users.php b/src/Cms/Users.php index df2f6c3361..401440293e 100644 --- a/src/Cms/Users.php +++ b/src/Cms/Users.php @@ -49,19 +49,19 @@ public function add($object): static if ($object instanceof self) { $this->data = array_merge($this->data, $object->data); - // add a user by id + // add a user by id } elseif ( is_string($object) === true && $user = App::instance()->user($object) ) { $this->__set($user->id(), $user); - // add a user object + // add a user object } elseif ($object instanceof User) { $this->__set($object->id(), $object); - // give a useful error message on invalid input; - // silently ignore "empty" values for compatibility with existing setups + // give a useful error message on invalid input; + // silently ignore "empty" values for compatibility with existing setups } elseif (in_array($object, [null, false, true], true) !== true) { throw new InvalidArgumentException('You must pass a Users or User object or an ID of an existing user to the Users collection'); } diff --git a/src/Content/Content.php b/src/Content/Content.php index 978c8d2710..01692871df 100644 --- a/src/Content/Content.php +++ b/src/Content/Content.php @@ -54,7 +54,7 @@ public function __call(string $name, array $arguments = []): Field */ public function __construct( array $data = [], - ModelWithContent $parent = null, + ModelWithContent|null $parent = null, bool $normalize = true ) { if ($normalize === true) { @@ -149,7 +149,7 @@ public function fields(): array * Returns either a single field object * or all registered fields */ - public function get(string $key = null): Field|array + public function get(string|null $key = null): Field|array { if ($key === null) { return $this->fields(); @@ -234,7 +234,7 @@ public function toArray(): array * @return $this */ public function update( - array $content = null, + array|null $content = null, bool $overwrite = false ): static { $content = array_change_key_case((array)$content, CASE_LOWER); diff --git a/src/Content/ContentTranslation.php b/src/Content/ContentTranslation.php index c04ec3284a..e341d15fb6 100644 --- a/src/Content/ContentTranslation.php +++ b/src/Content/ContentTranslation.php @@ -145,7 +145,7 @@ public function slug(): string|null * * @return $this */ - public function update(array $data = null, bool $overwrite = false): static + public function update(array|null $data = null, bool $overwrite = false): static { $data = array_change_key_case((array)$data); diff --git a/src/Content/Field.php b/src/Content/Field.php index 82ae4b6928..201ccc25fa 100644 --- a/src/Content/Field.php +++ b/src/Content/Field.php @@ -210,7 +210,7 @@ public function toString(): string * the modified field will be returned. Otherwise it * will return the field value. */ - public function value(string|Closure $value = null): mixed + public function value(string|Closure|null $value = null): mixed { if ($value === null) { return $this->value; diff --git a/src/Data/Txt.php b/src/Data/Txt.php index 7ea7d06f3f..985f5ea5c7 100644 --- a/src/Data/Txt.php +++ b/src/Data/Txt.php @@ -45,7 +45,7 @@ protected static function encodeValue(array|string|float $value): string // avoid problems with arrays if (is_array($value) === true) { $value = Data::encode($value, 'yaml'); - // avoid problems with localized floats + // avoid problems with localized floats } elseif (is_float($value) === true) { $value = Str::float($value); } diff --git a/src/Database/Query.php b/src/Database/Query.php index 1181b9880b..73dfe10b78 100644 --- a/src/Database/Query.php +++ b/src/Database/Query.php @@ -421,7 +421,7 @@ public function having(...$args): static * @param string|null $order * @return $this */ - public function order(string $order = null) + public function order(string|null $order = null) { $this->order = $order; return $this; @@ -828,13 +828,13 @@ protected function filterQuery(array $args, $current, string $mode = 'AND') if ($args[0] === null) { return $current; - // ->where('username like "myuser"'); + // ->where('username like "myuser"'); } elseif (is_string($args[0]) === true) { // simply add the entire string to the where clause // escaping or using bindings has to be done before calling this method $result = $args[0]; - // ->where(['username' => 'myuser']); + // ->where(['username' => 'myuser']); } elseif (is_array($args[0]) === true) { // simple array mode (AND operator) $sql = $this->database->sql()->values($this->table, $args[0], ' AND ', true, true); @@ -868,7 +868,7 @@ protected function filterQuery(array $args, $current, string $mode = 'AND') // store the bindings $this->bindings($args[1]); - // ->where('username like ?', 'myuser') + // ->where('username like ?', 'myuser') } elseif (is_string($args[0]) === true && is_scalar($args[1]) === true) { // prepared where clause $result = $args[0]; @@ -913,7 +913,7 @@ protected function filterQuery(array $args, $current, string $mode = 'AND') }; $result = $key . ' ' . $predicate . ' ' . $values; - // ->where('username', 'like', 'myuser'); + // ->where('username', 'like', 'myuser'); } else { $predicates = [ '=', '>=', '>', '<=', '<', '<>', '!=', '<=>', diff --git a/src/Database/Sql.php b/src/Database/Sql.php index 16349af1c5..877d61f641 100644 --- a/src/Database/Sql.php +++ b/src/Database/Sql.php @@ -146,7 +146,7 @@ public function columnTypes(): array * Combines an identifier (table and column) * * @param $values bool Whether the identifier is going to be used for a VALUES clause; - * only relevant for SQLite + * only relevant for SQLite */ public function combineIdentifier(string $table, string $column, bool $values = false): string { diff --git a/src/Filesystem/Dir.php b/src/Filesystem/Dir.php index 680789bddf..c12b7d1fea 100644 --- a/src/Filesystem/Dir.php +++ b/src/Filesystem/Dir.php @@ -149,7 +149,7 @@ public static function index( string $dir, bool $recursive = false, array|false|null $ignore = [], - string $path = null + string|null $path = null ): array { $result = []; $dir = realpath($dir); @@ -434,7 +434,7 @@ public static function make(string $dir, bool $recursive = true): bool */ public static function modified( string $dir, - string $format = null, + string|null $format = null, string|null $handler = null ): int|string { $modified = filemtime($dir); diff --git a/src/Filesystem/File.php b/src/Filesystem/File.php index 035c25ce64..fc9beec610 100644 --- a/src/Filesystem/File.php +++ b/src/Filesystem/File.php @@ -59,8 +59,8 @@ class File * @throws \Kirby\Exception\InvalidArgumentException When the model does not use the `Kirby\Filesystem\IsFile` trait */ public function __construct( - array|string $props = null, - string $url = null + array|string|null $props = null, + string|null $url = null ) { // Legacy support for old constructor of // the `Kirby\Image\Image` class diff --git a/src/Filesystem/Mime.php b/src/Filesystem/Mime.php index 5b839183b9..2bb2a03675 100644 --- a/src/Filesystem/Mime.php +++ b/src/Filesystem/Mime.php @@ -251,7 +251,7 @@ public static function matches(string $test, string $wildcard): bool /** * Returns the extension for a given MIME type */ - public static function toExtension(string $mime = null): string|false + public static function toExtension(string|null $mime = null): string|false { foreach (static::$types as $key => $value) { if (is_array($value) === true && in_array($mime, $value) === true) { @@ -269,7 +269,7 @@ public static function toExtension(string $mime = null): string|false /** * Returns all available extensions for a given MIME type */ - public static function toExtensions(string $mime = null, bool $matchWildcards = false): array + public static function toExtensions(string|null $mime = null, bool $matchWildcards = false): array { $extensions = []; $testMime = fn (string $v) => static::matches($v, $mime); diff --git a/src/Form/Field.php b/src/Form/Field.php index cb95fd49da..114a826892 100644 --- a/src/Form/Field.php +++ b/src/Form/Field.php @@ -127,7 +127,7 @@ public static function defaults(): array /** * Sets the focus on this field when the form loads. Only the first field with this label gets */ - 'autofocus' => function (bool $autofocus = null): bool { + 'autofocus' => function (bool|null $autofocus = null): bool { return $autofocus ?? false; }, /** @@ -145,7 +145,7 @@ public static function defaults(): array /** * If `true`, the field is no longer editable and will not be saved */ - 'disabled' => function (bool $disabled = null): bool { + 'disabled' => function (bool|null $disabled = null): bool { return $disabled ?? false; }, /** @@ -157,7 +157,7 @@ public static function defaults(): array /** * Optional icon that will be shown at the end of the field */ - 'icon' => function (string $icon = null) { + 'icon' => function (string|null $icon = null) { return $icon; }, /** @@ -175,7 +175,7 @@ public static function defaults(): array /** * If `true`, the field has to be filled in correctly to be saved. */ - 'required' => function (bool $required = null): bool { + 'required' => function (bool|null $required = null): bool { return $required ?? false; }, /** diff --git a/src/Form/Field/BlocksField.php b/src/Form/Field/BlocksField.php index e37d373e6e..2d66a6b01e 100644 --- a/src/Form/Field/BlocksField.php +++ b/src/Form/Field/BlocksField.php @@ -214,7 +214,7 @@ public function routes(): array 'action' => function ( string $fieldsetType, string $fieldName, - string $path = null + string|null $path = null ) use ($field) { $fields = $field->fields($fieldsetType); $field = $field->form($fields)->field($fieldName); @@ -276,7 +276,7 @@ protected function setFieldsets( ); } - protected function setGroup(string $group = null): void + protected function setGroup(string|null $group = null): void { $this->group = $group; } diff --git a/src/Form/Field/LayoutField.php b/src/Form/Field/LayoutField.php index 2e595c050f..d92c35260b 100644 --- a/src/Form/Field/LayoutField.php +++ b/src/Form/Field/LayoutField.php @@ -175,7 +175,7 @@ public function routes(): array 'method' => 'ALL', 'action' => function ( string $fieldName, - string $path = null + string|null $path = null ) use ($field): array { $form = $field->attrsForm(); $field = $form->field($fieldName); diff --git a/src/Form/FieldClass.php b/src/Form/FieldClass.php index cc4115efc2..613122c38a 100644 --- a/src/Form/FieldClass.php +++ b/src/Form/FieldClass.php @@ -610,7 +610,7 @@ protected function valueFromYaml(mixed $value): array } protected function valueToJson( - array $value = null, + array|null $value = null, bool $pretty = false ): string { $constants = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE; @@ -622,7 +622,7 @@ protected function valueToJson( return json_encode($value, $constants); } - protected function valueToYaml(array $value = null): string + protected function valueToYaml(array|null $value = null): string { return Data::encode($value, 'yaml'); } diff --git a/src/Form/Fields.php b/src/Form/Fields.php index ef46f2e8e5..95c8fec9b5 100644 --- a/src/Form/Fields.php +++ b/src/Form/Fields.php @@ -39,7 +39,7 @@ public function __set(string $name, $field): void * array and also does that for every * included field. */ - public function toArray(Closure $map = null): array + public function toArray(Closure|null $map = null): array { $array = []; diff --git a/src/Form/Mixin/Max.php b/src/Form/Mixin/Max.php index 3141bbe729..1641917de2 100644 --- a/src/Form/Mixin/Max.php +++ b/src/Form/Mixin/Max.php @@ -11,7 +11,7 @@ public function max(): int|null return $this->max; } - protected function setMax(int $max = null) + protected function setMax(int|null $max = null) { $this->max = $max; } diff --git a/src/Form/Mixin/Min.php b/src/Form/Mixin/Min.php index 1b585e14bd..aa57af507d 100644 --- a/src/Form/Mixin/Min.php +++ b/src/Form/Mixin/Min.php @@ -11,7 +11,7 @@ public function min(): int|null return $this->min; } - protected function setMin(int $min = null) + protected function setMin(int|null $min = null) { $this->min = $min; } diff --git a/src/Http/Environment.php b/src/Http/Environment.php index bb8f4f6521..c7b1f05026 100644 --- a/src/Http/Environment.php +++ b/src/Http/Environment.php @@ -153,8 +153,8 @@ public function cli(): bool * @param array|null $info Optional override for `$_SERVER` */ public function detect( - array $options = null, - array $info = null + array|null $options = null, + array|null $info = null ): array { $defaults = [ 'cli' => null, @@ -178,11 +178,11 @@ public function detect( if ($options['allowed'] === '*' || $options['allowed'] === ['*']) { $this->detectAuto(true); - // fixed environments + // fixed environments } elseif (empty($options['allowed']) === false) { $this->detectAllowed($options['allowed']); - // secure auto-detection + // secure auto-detection } else { $this->detectAuto(); } diff --git a/src/Http/Route.php b/src/Http/Route.php index 7d6dd7da3c..8bc8348f10 100644 --- a/src/Http/Route.php +++ b/src/Http/Route.php @@ -63,7 +63,7 @@ class Route /** * Magic getter for route attributes */ - public function __call(string $key, array $args = null): mixed + public function __call(string $key, array|null $args = null): mixed { return $this->attributes[$key] ?? null; } diff --git a/src/Http/Url.php b/src/Http/Url.php index 93600409da..8139b94124 100644 --- a/src/Http/Url.php +++ b/src/Http/Url.php @@ -220,7 +220,7 @@ public static function stripFragment(string|null $url = null): string */ public static function to( string|null $path = null, - array $options = null + array|null $options = null ): string { // make sure $path is string $path ??= ''; diff --git a/src/Option/Option.php b/src/Option/Option.php index 3e587417d5..7de4b424aa 100644 --- a/src/Option/Option.php +++ b/src/Option/Option.php @@ -28,7 +28,7 @@ public function __construct( $this->text ??= new NodeText(['en' => $this->value]); } - public static function factory(string|int|float|null|array $props): static + public static function factory(string|int|float|array|null $props): static { if (is_array($props) === false) { $props = ['value' => $props]; diff --git a/src/Panel/Panel.php b/src/Panel/Panel.php index e6f9ff67a5..b88bcab6cc 100644 --- a/src/Panel/Panel.php +++ b/src/Panel/Panel.php @@ -235,7 +235,7 @@ public static function response($result, array $options = []): Response if ($result === null || $result === false) { $result = new NotFoundException('The data could not be found'); - // interpret strings as errors + // interpret strings as errors } elseif (is_string($result) === true) { $result = new Exception($result); } diff --git a/src/Panel/View.php b/src/Panel/View.php index 9058e5eec6..c857710cd0 100644 --- a/src/Panel/View.php +++ b/src/Panel/View.php @@ -330,15 +330,15 @@ public static function response($data, array $options = []): Response if ($data instanceof Redirect) { return Response::redirect($data->location(), $data->code()); - // handle Kirby exceptions + // handle Kirby exceptions } elseif ($data instanceof Exception) { $data = static::error($data->getMessage(), $data->getHttpCode()); - // handle regular exceptions + // handle regular exceptions } elseif ($data instanceof Throwable) { $data = static::error($data->getMessage(), 500); - // only expect arrays from here on + // only expect arrays from here on } elseif (is_array($data) === false) { $data = static::error('Invalid Panel response', 500); } diff --git a/src/Parsley/Parsley.php b/src/Parsley/Parsley.php index 3f2242e204..b6d834b193 100644 --- a/src/Parsley/Parsley.php +++ b/src/Parsley/Parsley.php @@ -212,7 +212,7 @@ public function mergeOrAppend(array $block): void ) { $this->blocks[$lastIndex]['content']['text'] .= ' ' . $block['content']['text']; - // append + // append } else { $this->blocks[] = $block; } diff --git a/src/Query/Expression.php b/src/Query/Expression.php index f205c302e9..84928c3f5d 100644 --- a/src/Query/Expression.php +++ b/src/Query/Expression.php @@ -25,7 +25,7 @@ public function __construct( /** * Parses an expression string into its parts */ - public static function factory(string $expression, Query $parent = null): static|Segments + public static function factory(string $expression, Query|null $parent = null): static|Segments { // split into different expression parts and operators $parts = static::parse($expression); diff --git a/src/Query/Query.php b/src/Query/Query.php index ab6381cb83..20cefa5a3f 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -131,12 +131,12 @@ public function resolve(array|object $data = []): mixed Query::$entries['t'] = function ( string $key, - string|array $fallback = null, - string $locale = null + string|array|null $fallback = null, + string|null $locale = null ): string|null { return I18n::translate($key, $fallback, $locale); }; -Query::$entries['user'] = function (string $id = null): User|null { +Query::$entries['user'] = function (string|null $id = null): User|null { return App::instance()->user($id); }; diff --git a/src/Query/Segments.php b/src/Query/Segments.php index d2af4701c9..c4069a18ce 100644 --- a/src/Query/Segments.php +++ b/src/Query/Segments.php @@ -28,7 +28,7 @@ public function __construct( * Split query string into segments by dot * but not inside (nested) parens */ - public static function factory(string $query, Query $parent = null): static + public static function factory(string $query, Query|null $parent = null): static { $segments = static::parse($query); $position = 0; diff --git a/src/Session/Session.php b/src/Session/Session.php index e5302582a8..39478cd007 100644 --- a/src/Session/Session.php +++ b/src/Session/Session.php @@ -149,7 +149,7 @@ public function token(): string|null * @param string|null $mode Optional new transmission mode * @return string Transmission mode */ - public function mode(string $mode = null): string + public function mode(string|null $mode = null): string { if ($mode !== null) { // only allow this if this is a new session, otherwise the change @@ -214,7 +214,7 @@ public function expiryTime(string|int|null $expiryTime = null): int * @param int|null $duration Optional new duration in seconds to set * @return int Number of seconds */ - public function duration(int $duration = null): int + public function duration(int|null $duration = null): int { if ($duration !== null) { // verify that the duration is at least 1 second diff --git a/src/Session/Sessions.php b/src/Session/Sessions.php index 581d144b78..0606b3304a 100644 --- a/src/Session/Sessions.php +++ b/src/Session/Sessions.php @@ -105,7 +105,7 @@ public function create(array $options = []): Session * @param string $token Session token, either including or without the key * @param string|null $mode Optional transmission mode override */ - public function get(string $token, string $mode = null): Session + public function get(string $token, string|null $mode = null): Session { return $this->cache[$token] ??= new Session( $this, diff --git a/src/Toolkit/A.php b/src/Toolkit/A.php index 1970cc9861..d8ac7a2942 100644 --- a/src/Toolkit/A.php +++ b/src/Toolkit/A.php @@ -508,7 +508,7 @@ public static function merge(array|int ...$arrays): array ) { $merged[] = $value; - // recursively merge the two array values + // recursively merge the two array values } elseif ( is_array($value) === true && isset($merged[$key]) === true && @@ -516,7 +516,7 @@ public static function merge(array|int ...$arrays): array ) { $merged[$key] = static::merge($merged[$key], $value, $mode); - // simply overwrite with the value from the second array + // simply overwrite with the value from the second array } else { $merged[$key] = $value; } diff --git a/src/Toolkit/Collection.php b/src/Toolkit/Collection.php index 7c9fa166a2..a962bcb52d 100644 --- a/src/Toolkit/Collection.php +++ b/src/Toolkit/Collection.php @@ -198,7 +198,7 @@ public function clone() * @param array|null $data * @return array|$this */ - public function data(array $data = null) + public function data(array|null $data = null) { if ($data === null) { return $this->data; @@ -775,7 +775,7 @@ public function pagination() * @param bool $unique * @return array */ - public function pluck(string $field, string $split = null, bool $unique = false): array + public function pluck(string $field, string|null $split = null, bool $unique = false): array { $result = []; @@ -956,7 +956,7 @@ public function shuffle() * @param int|null $limit The optional number of elements to return * @return $this|static */ - public function slice(int $offset = 0, int $limit = null) + public function slice(int $offset = 0, int|null $limit = null) { if ($offset === 0 && $limit === null) { return $this; @@ -1027,7 +1027,7 @@ public function sort() } elseif ($arg === SORT_DESC || $argLower === 'desc') { $fields[$currentField]['direction'] = SORT_DESC; - // other string: the field name + // other string: the field name } elseif (is_string($arg) === true) { $values = []; @@ -1041,7 +1041,7 @@ public function sort() $fields[] = ['field' => $arg, 'values' => $values]; - // callable: custom field values + // callable: custom field values } elseif (is_callable($arg) === true) { $values = []; @@ -1055,7 +1055,7 @@ public function sort() $fields[] = ['field' => null, 'values' => $values]; - // flags + // flags } else { $fields[$currentField]['flags'] = $arg; } @@ -1126,7 +1126,7 @@ public function sortBy(...$args) * @param \Closure|null $map * @return array */ - public function toArray(Closure $map = null): array + public function toArray(Closure|null $map = null): array { if ($map !== null) { return array_map($map, $this->data); @@ -1163,7 +1163,7 @@ public function toString(): string * @param Closure|null $map * @return array */ - public function values(Closure $map = null): array + public function values(Closure|null $map = null): array { $data = $map === null ? $this->data : array_map($map, $this->data); return array_values($data); @@ -1181,7 +1181,7 @@ public function values(Closure $map = null): array * @param \Closure|null $fallback * @return mixed */ - public function when($condition, Closure $callback, Closure $fallback = null) + public function when($condition, Closure $callback, Closure|null $fallback = null) { if ($condition) { return $callback->call($this, $condition); diff --git a/src/Toolkit/Facade.php b/src/Toolkit/Facade.php index b1547ec172..04e9e15f10 100644 --- a/src/Toolkit/Facade.php +++ b/src/Toolkit/Facade.php @@ -23,7 +23,7 @@ abstract public static function instance(); /** * Proxy for all public instance calls */ - public static function __callStatic(string $method, array $args = null) + public static function __callStatic(string $method, array|null $args = null) { return static::instance()->$method(...$args); } diff --git a/src/Toolkit/Html.php b/src/Toolkit/Html.php index 56c4ed845a..9170c679a8 100644 --- a/src/Toolkit/Html.php +++ b/src/Toolkit/Html.php @@ -405,7 +405,7 @@ public static function tag( string $name, array|string|null $content = '', array $attr = [], - string $indent = null, + string|null $indent = null, int $level = 0 ): string { // treat an explicit `null` value as an empty tag diff --git a/src/Toolkit/I18n.php b/src/Toolkit/I18n.php index 0c790de4d8..793072ce34 100644 --- a/src/Toolkit/I18n.php +++ b/src/Toolkit/I18n.php @@ -78,7 +78,7 @@ public static function form(int $count, bool $none = false): string /** * Formats a number */ - public static function formatNumber(int|float $number, string $locale = null): string + public static function formatNumber(int|float $number, string|null $locale = null): string { $locale ??= static::locale(); $formatter = static::decimalNumberFormatter($locale); @@ -108,7 +108,7 @@ public static function locale(): string */ public static function template( string $key, - string|array $fallback = null, + string|array|null $fallback = null, array|null $replace = null, string|null $locale = null ): string { @@ -130,8 +130,8 @@ public static function template( */ public static function translate( string|array|null $key, - string|array $fallback = null, - string $locale = null + string|array|null $fallback = null, + string|null $locale = null ): string|array|Closure|null { // use current locale if no specific is passed $locale ??= static::locale(); @@ -242,7 +242,7 @@ public static function translate( * by locale. If the translation does not exist * yet, the loader will try to load it, if defined. */ - public static function translation(string $locale = null): array + public static function translation(string|null $locale = null): array { $locale ??= static::locale(); @@ -304,7 +304,7 @@ class_exists('NumberFormatter') !== true public static function translateCount( string $key, int $count, - string $locale = null, + string|null $locale = null, bool $formatNumber = true ) { $locale ??= static::locale(); diff --git a/src/Toolkit/Properties.php b/src/Toolkit/Properties.php index 8ab1a77e72..64575ba95f 100644 --- a/src/Toolkit/Properties.php +++ b/src/Toolkit/Properties.php @@ -96,7 +96,7 @@ protected function setOptionalProperties(array $props, array $optional) } } - protected function setProperties($props, array $keys = null) + protected function setProperties($props, array|null $keys = null) { foreach (get_object_vars($this) as $name => $default) { if ($name === 'propertyData') { diff --git a/src/Toolkit/Silo.php b/src/Toolkit/Silo.php index d377dccb7b..ace941b2f8 100644 --- a/src/Toolkit/Silo.php +++ b/src/Toolkit/Silo.php @@ -30,7 +30,7 @@ public static function set(string|array $key, $value = null): array return static::$data; } - public static function get(string|array $key = null, $default = null) + public static function get(string|array|null $key = null, $default = null) { if ($key === null) { return static::$data; @@ -42,7 +42,7 @@ public static function get(string|array $key = null, $default = null) /** * Removes an item from the data array */ - public static function remove(string $key = null): array + public static function remove(string|null $key = null): array { // reset the entire array if ($key === null) { diff --git a/src/Toolkit/Str.php b/src/Toolkit/Str.php index 73fdbf647e..c776848709 100644 --- a/src/Toolkit/Str.php +++ b/src/Toolkit/Str.php @@ -263,7 +263,7 @@ public static function beforeEnd( * Returns everything between two strings from the first occurrence of a given string */ public static function between( - string $string = null, + string|null $string = null, string $start, string $end ): string { @@ -275,7 +275,7 @@ public static function between( * * @param string $value The string to convert */ - public static function camel(string $value = null): string + public static function camel(string|null $value = null): string { return lcfirst(static::studly($value)); } @@ -286,7 +286,7 @@ public static function camel(string $value = null): string * * @param string $value The string to convert */ - public static function camelToKebab(string $value = null): string + public static function camelToKebab(string|null $value = null): string { return static::lower(preg_replace('!([a-z0-9])([A-Z])!', '$1-$2', $value)); } @@ -295,7 +295,7 @@ public static function camelToKebab(string $value = null): string * Checks if a str contains another string */ public static function contains( - string $string = null, + string|null $string = null, string $needle, bool $caseInsensitive = false ): bool { @@ -316,7 +316,7 @@ public static function contains( */ public static function date( int|null $time = null, - string|IntlDateFormatter $format = null, + string|IntlDateFormatter|null $format = null, string|null $handler = null ): string|int|false { if (is_null($format) === true) { @@ -365,7 +365,7 @@ public static function date( public static function convert( string $string, string $targetEncoding, - string $sourceEncoding = null + string|null $sourceEncoding = null ): string { // detect the source encoding if not passed as third argument $sourceEncoding ??= static::encoding($string); @@ -414,7 +414,7 @@ public static function encoding(string $string): string * Checks if a string ends with the passed needle */ public static function endsWith( - string $string = null, + string|null $string = null, string $needle, bool $caseInsensitive = false ): bool { @@ -574,7 +574,7 @@ public static function increment( /** * Convert a string to kebab case. */ - public static function kebab(string $value = null): string + public static function kebab(string|null $value = null): string { return static::snake($value, '-'); } @@ -582,7 +582,7 @@ public static function kebab(string $value = null): string /** * Convert a kebab case string to camel case. */ - public static function kebabToCamel(string $value = null): string + public static function kebabToCamel(string|null $value = null): string { return ucfirst(preg_replace_callback( '/-(.)/', @@ -594,7 +594,7 @@ public static function kebabToCamel(string $value = null): string /** * A UTF-8 safe version of strlen() */ - public static function length(string $string = null): int + public static function length(string|null $string = null): int { return mb_strlen($string ?? '', 'UTF-8'); } @@ -602,7 +602,7 @@ public static function length(string $string = null): int /** * A UTF-8 safe version of strtolower() */ - public static function lower(string $string = null): string + public static function lower(string|null $string = null): string { return mb_strtolower($string ?? '', 'UTF-8'); } @@ -707,7 +707,7 @@ public static function pool( * @throws \Kirby\Exception\InvalidArgumentException for empty $needle */ public static function position( - string $string = null, + string|null $string = null, string $needle, bool $caseInsensitive = false ): int|false { @@ -739,7 +739,7 @@ public static function query(string $query, array $data = []) * @param string $type Pool type (type of allowed characters) */ public static function random( - int $length = null, + int|null $length = null, string $type = 'alphaNum' ): string|false { $length ??= random_int(5, 10); @@ -967,7 +967,7 @@ public static function rtrim(string $string, string $trim = ' '): string * @return string The filled-in and partially escaped string */ public static function safeTemplate( - string $string = null, + string|null $string = null, array $data = [], array $options = [] ): string { @@ -1024,7 +1024,7 @@ public static function safeTemplate( * @return string The shortened string */ public static function short( - string $string = null, + string|null $string = null, int $length = 0, string $appendix = '…' ): string { @@ -1129,9 +1129,9 @@ public static function similarity( * @return string The safe string */ public static function slug( - string $string = null, - string $separator = null, - string $allowed = null, + string|null $string = null, + string|null $separator = null, + string|null $allowed = null, int|false $maxlength = 128 ): string { $separator ??= static::$defaults['slug']['separator']; @@ -1176,7 +1176,7 @@ public static function slug( * Convert a string to snake case. */ public static function snake( - string $value = null, + string|null $value = null, string $delimiter = '_' ): string { if (ctype_lower($value) === false) { @@ -1230,7 +1230,7 @@ public static function split( * Checks if a string starts with the passed needle */ public static function startsWith( - string $string = null, + string|null $string = null, string $needle, bool $caseInsensitive = false ): bool { @@ -1247,7 +1247,7 @@ public static function startsWith( * * @param string $value The string to convert */ - public static function studly(string $value = null): string + public static function studly(string|null $value = null): string { $value = str_replace(['-', '_'], ' ', $value); $value = ucwords($value); @@ -1258,9 +1258,9 @@ public static function studly(string $value = null): string * A UTF-8 safe version of substr() */ public static function substr( - string $string = null, + string|null $string = null, int $start = 0, - int $length = null + int|null $length = null ): string { return mb_substr($string ?? '', $start, $length, 'UTF-8'); } @@ -1287,7 +1287,7 @@ public static function substr( * @return string The filled-in string */ public static function template( - string $string = null, + string|null $string = null, array $data = [], array $options = [] ): string { @@ -1384,7 +1384,7 @@ public static function trim(string $string, string $trim = ' '): string /** * A UTF-8 safe version of ucfirst() */ - public static function ucfirst(string $string = null): string + public static function ucfirst(string|null $string = null): string { $first = static::substr($string, 0, 1); $rest = static::substr($string, 1); @@ -1394,7 +1394,7 @@ public static function ucfirst(string $string = null): string /** * A UTF-8 safe version of ucwords() */ - public static function ucwords(string $string = null): string + public static function ucwords(string|null $string = null): string { return mb_convert_case($string ?? '', MB_CASE_TITLE, 'UTF-8'); } @@ -1409,7 +1409,7 @@ public static function ucwords(string $string = null): string * * */ - public static function unhtml(string $string = null): string + public static function unhtml(string|null $string = null): string { return Html::decode($string); } @@ -1434,7 +1434,7 @@ public static function until( /** * A UTF-8 safe version of strotoupper() */ - public static function upper(string $string = null): string + public static function upper(string|null $string = null): string { return mb_strtoupper($string ?? '', 'UTF-8'); } @@ -1472,7 +1472,7 @@ public static function uuid(): string * typographical widows at the end of a paragraph – * that's a single word in the last line */ - public static function widont(string $string = null): string + public static function widont(string|null $string = null): string { // make sure $string is string $string ??= ''; @@ -1504,7 +1504,7 @@ public static function widont(string $string = null): string public static function wrap( string $string, string $before, - string $after = null + string|null $after = null ): string { return $before . $string . ($after ?? $before); } diff --git a/src/Toolkit/V.php b/src/Toolkit/V.php index 1170542a77..1d36255151 100644 --- a/src/Toolkit/V.php +++ b/src/Toolkit/V.php @@ -306,7 +306,7 @@ public static function __callStatic(string $method, array $arguments): bool * Pass an operator as second argument and another date as * third argument to compare them. */ - 'date' => function (string|null $value, string $operator = null, string $test = null): bool { + 'date' => function (string|null $value, string|null $operator = null, string|null $test = null): bool { // make sure $value is a string $value ??= ''; @@ -474,28 +474,28 @@ public static function __callStatic(string $method, array $arguments): bool /** * Checks if the number of characters in the value equals or is below the given maximum */ - 'maxLength' => function (string $value = null, $max): bool { + 'maxLength' => function (string|null $value = null, $max): bool { return Str::length(trim($value)) <= $max; }, /** * Checks if the number of characters in the value equals or is greater than the given minimum */ - 'minLength' => function (string $value = null, $min): bool { + 'minLength' => function (string|null $value = null, $min): bool { return Str::length(trim($value)) >= $min; }, /** * Checks if the number of words in the value equals or is below the given maximum */ - 'maxWords' => function (string $value = null, $max): bool { + 'maxWords' => function (string|null $value = null, $max): bool { return V::max(explode(' ', trim($value)), $max) === true; }, /** * Checks if the number of words in the value equals or is below the given maximum */ - 'minWords' => function (string $value = null, $min): bool { + 'minWords' => function (string|null $value = null, $min): bool { return V::min(explode(' ', trim($value)), $min) === true; }, @@ -628,7 +628,7 @@ public static function __callStatic(string $method, array $arguments): bool /** * Checks for a valid Uuid, optionally for specific model type */ - 'uuid' => function (string $value, string $type = null): bool { + 'uuid' => function (string $value, string|null $type = null): bool { return Uuid::is($value, $type); } ]; diff --git a/src/Toolkit/Xml.php b/src/Toolkit/Xml.php index e140d5fec5..72a985501c 100644 --- a/src/Toolkit/Xml.php +++ b/src/Toolkit/Xml.php @@ -373,7 +373,7 @@ public static function tag( string $name, array|string|null $content = '', array $attr = [], - string $indent = null, + string|null $indent = null, int $level = 0 ): string { $attr = static::attr($attr); diff --git a/src/Uuid/Uri.php b/src/Uuid/Uri.php index 33295c77f4..34faf1d530 100644 --- a/src/Uuid/Uri.php +++ b/src/Uuid/Uri.php @@ -61,7 +61,7 @@ public function base(): string|null * Returns the ID part of the UUID string * (and sets it when new one passed) */ - public function host(string $host = null): string|null + public function host(string|null $host = null): string|null { if ($host !== null) { return $this->host = $host; diff --git a/tests/Cache/mocks.php b/tests/Cache/mocks.php index c50f3b31fb..d599237f3a 100644 --- a/tests/Cache/mocks.php +++ b/tests/Cache/mocks.php @@ -22,14 +22,14 @@ class TestCache extends Cache { public $store = []; - public function set(string $key, $value, int $minutes = 0, int $created = null): bool + public function set(string $key, $value, int $minutes = 0, int|null $created = null): bool { $value = new Value($value, $minutes, $created); $this->store[$key] = $value; return true; } - public function retrieve(string $key): ?Value + public function retrieve(string $key): Value|null { return $this->store[$key] ?? null; } diff --git a/tests/Cms/App/AppComponentsTest.php b/tests/Cms/App/AppComponentsTest.php index bc3f1c8075..c63bc217de 100644 --- a/tests/Cms/App/AppComponentsTest.php +++ b/tests/Cms/App/AppComponentsTest.php @@ -159,7 +159,7 @@ public function testMarkdownPlugin() { $this->kirby = $this->kirby->clone([ 'components' => [ - 'markdown' => function (App $kirby, string $text = null, array $options = []) { + 'markdown' => function (App $kirby, string|null $text = null, array $options = []) { $result = Html::encode($text); if (($options['inline'] ?? false) === false) { diff --git a/tests/Cms/Files/FileTest.php b/tests/Cms/Files/FileTest.php index a523b01fad..8f31b960cf 100644 --- a/tests/Cms/Files/FileTest.php +++ b/tests/Cms/Files/FileTest.php @@ -17,7 +17,7 @@ class FileTest extends TestCase { public const TMP = KIRBY_TMP_DIR . '/Cms.File'; - protected function defaults(?App $kirby = null): array + protected function defaults(App|null $kirby = null): array { $page = new Page([ 'kirby' => $kirby, diff --git a/tests/Cms/Sections/mixins/LayoutMixinTest.php b/tests/Cms/Sections/mixins/LayoutMixinTest.php index 5aaca2444b..9be7ccde0c 100644 --- a/tests/Cms/Sections/mixins/LayoutMixinTest.php +++ b/tests/Cms/Sections/mixins/LayoutMixinTest.php @@ -22,10 +22,10 @@ public function setUp(): void Section::$types['test'] = Section::$types['pages'] = [ 'mixins' => ['layout'], 'props' => $props = [ - 'info' => function (string $info = null) { + 'info' => function (string|null $info = null) { return $info; }, - 'text' => function (string $text = null) { + 'text' => function (string|null $text = null) { return $text; } ] diff --git a/tests/Cms/Sections/mixins/SortMixinTest.php b/tests/Cms/Sections/mixins/SortMixinTest.php index bc00e722e5..682ff6c9de 100644 --- a/tests/Cms/Sections/mixins/SortMixinTest.php +++ b/tests/Cms/Sections/mixins/SortMixinTest.php @@ -22,7 +22,7 @@ public function setUp(): void Section::$types['test'] = [ 'mixins' => ['sort'], 'props' => [ - 'query' => function (string $query = null) { + 'query' => function (string|null $query = null) { return $query; } ] @@ -31,7 +31,7 @@ public function setUp(): void Section::$types['pages'] = [ 'mixins' => ['sort'], 'props' => [ - 'status' => function (string $status = null) { + 'status' => function (string|null $status = null) { return $status; }, ] diff --git a/tests/Cms/TestCase.php b/tests/Cms/TestCase.php index 60ae7d9f3e..9c6ca955b1 100644 --- a/tests/Cms/TestCase.php +++ b/tests/Cms/TestCase.php @@ -56,7 +56,7 @@ public function pages() return $this->site()->children(); } - public function page(string $id = null) + public function page(string|null $id = null) { if ($id !== null) { return $this->site()->find($id); diff --git a/tests/Form/Fields/Mixins/FilePickerMixinTest.php b/tests/Form/Fields/Mixins/FilePickerMixinTest.php index 6a837f20ab..e49af812ee 100644 --- a/tests/Form/Fields/Mixins/FilePickerMixinTest.php +++ b/tests/Form/Fields/Mixins/FilePickerMixinTest.php @@ -169,7 +169,7 @@ public function testCustomQuery() 'test' => [ 'mixins' => ['filepicker'], 'props' => [ - 'query' => function (string $query = null) { + 'query' => function (string|null $query = null) { return $query; } ], @@ -213,7 +213,7 @@ public function testMap() 'test' => [ 'mixins' => ['filepicker'], 'props' => [ - 'query' => function (string $query = null) { + 'query' => function (string|null $query = null) { return $query; } ], diff --git a/tests/Form/Fields/TestCase.php b/tests/Form/Fields/TestCase.php index d3b2fc26a0..6b107f8f5c 100644 --- a/tests/Form/Fields/TestCase.php +++ b/tests/Form/Fields/TestCase.php @@ -39,7 +39,7 @@ public function app() return $this->app; } - public function field(string $type, array $attr = [], ?Fields $formFields = null) + public function field(string $type, array $attr = [], Fields|null $formFields = null) { $page = new Page(['slug' => 'test']); return Field::factory($type, array_merge(['model' => $page], $attr), $formFields); diff --git a/tests/Http/mocks.php b/tests/Http/mocks.php index 024b0c4617..db55225b1b 100644 --- a/tests/Http/mocks.php +++ b/tests/Http/mocks.php @@ -17,7 +17,7 @@ class IniStore /** * Mock for the PHP headers_sent() function (otherwise not available on CLI) */ -function headers_sent(string &$file = null, int &$line = null): bool +function headers_sent(string|null &$file = null, int|null &$line = null): bool { if (defined('KIRBY_TESTING') !== true || KIRBY_TESTING !== true) { throw new Exception('Mock headers_sent() was loaded outside of the test environment. This should never happen.'); diff --git a/tests/Image/DarkroomTest.php b/tests/Image/DarkroomTest.php index 3b164ad1a5..b081c9c990 100644 --- a/tests/Image/DarkroomTest.php +++ b/tests/Image/DarkroomTest.php @@ -8,7 +8,7 @@ class DarkroomTest extends TestCase { public const FIXTURES = __DIR__ . '/fixtures'; - public function file(string $driver = null) + public function file(string|null $driver = null) { if ($driver !== null) { return static::FIXTURES . '/image/cat-' . $driver . '.jpg'; diff --git a/tests/Panel/Areas/AreaTestCase.php b/tests/Panel/Areas/AreaTestCase.php index d7905a552e..760e1fb452 100644 --- a/tests/Panel/Areas/AreaTestCase.php +++ b/tests/Panel/Areas/AreaTestCase.php @@ -155,7 +155,7 @@ public function login(string $user = 'test@getkirby.com'): void $this->app->impersonate($user); } - public function response(string $path = null, bool $toJson = false) + public function response(string|null $path = null, bool $toJson = false) { $response = Panel::router($path); @@ -221,7 +221,7 @@ public function tearDown(): void App::destroy(); } - public function view(string $path = null): array + public function view(string|null $path = null): array { return $this->response($path, true)['$view']; } diff --git a/tests/Panel/Areas/PluginSearchesTest.php b/tests/Panel/Areas/PluginSearchesTest.php index 652ff6c530..8c00d44fec 100644 --- a/tests/Panel/Areas/PluginSearchesTest.php +++ b/tests/Panel/Areas/PluginSearchesTest.php @@ -22,7 +22,7 @@ public function testLegacyPluginSearch(): void 'search' => 'test', 'searches' => [ 'test' => [ - 'query' => function (string $query = null) { + 'query' => function (string|null $query = null) { return [['a'], ['b'], ['c']]; }, ] diff --git a/tests/Toolkit/DomTest.php b/tests/Toolkit/DomTest.php index 80fe487a7c..ab43cecbea 100644 --- a/tests/Toolkit/DomTest.php +++ b/tests/Toolkit/DomTest.php @@ -219,7 +219,7 @@ public static function parseSaveProvider(): array * @covers ::exportHtml * @covers ::exportXml */ - public function testParseSave(string $type, string $code, string $expected = null) + public function testParseSave(string $type, string $code, string|null $expected = null) { $dom = new Dom($code, $type); $this->assertSame($expected ?? $code, $dom->toString()); @@ -356,7 +356,7 @@ public static function parseSaveNormalizeProvider(): array * @covers ::exportHtml * @covers ::exportXml */ - public function testParseSaveNormalize(string $type, string $code, string $expected = null) + public function testParseSaveNormalize(string $type, string $code, string|null $expected = null) { $dom = new Dom($code, $type); $this->assertSame($expected ?? $code, $dom->toString(true)); From ebf4b840a41ae76207c0b6312af37b27d2e4ba3c Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Sun, 24 Nov 2024 12:58:43 +0100 Subject: [PATCH 06/12] Remove PHP 8.1 from CI tests --- .github/workflows/backend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 9e804c1f90..e7b0ef6fbd 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -57,7 +57,7 @@ jobs: timeout-minutes: 5 strategy: matrix: - php: ["8.1", "8.2", "8.3", "8.4"] + php: ["8.2", "8.3", "8.4"] env: extensions: mbstring, ctype, curl, gd, apcu, memcached ini: apc.enabled=1, apc.enable_cli=1, pcov.directory=., "pcov.exclude=\"~(vendor|tests)~\"" From 39accda4b1e4de313fdace7ffd00dbac70d019bc Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Sun, 24 Nov 2024 13:00:47 +0100 Subject: [PATCH 07/12] CI: upgrade PHP CS Fixer --- .github/workflows/backend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index e7b0ef6fbd..b51abc30ea 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -259,7 +259,7 @@ jobs: with: php-version: ${{ env.php }} coverage: none - tools: php-cs-fixer:3.13.0 + tools: php-cs-fixer:3.52.1 - name: Cache analysis data id: finishPrepare From f774a41ba19ad373adf7def495fa9f1f40a12fc8 Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Sat, 7 Dec 2024 13:25:14 +0100 Subject: [PATCH 08/12] Fix implicitly required parameters --- config/areas/site/searches.php | 4 ++-- config/areas/users/searches.php | 2 +- src/Cms/Blueprint.php | 2 +- src/Cms/Media.php | 2 +- src/Toolkit/Str.php | 10 +++++----- src/Toolkit/V.php | 8 ++++---- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/config/areas/site/searches.php b/config/areas/site/searches.php index c686936459..f40f218bc5 100644 --- a/config/areas/site/searches.php +++ b/config/areas/site/searches.php @@ -8,7 +8,7 @@ 'pages' => [ 'label' => I18n::translate('pages'), 'icon' => 'page', - 'query' => function (string|null $query = null, int $limit, int $page) { + 'query' => function (string|null $query, int $limit, int $page) { $kirby = App::instance(); $pages = $kirby->site() ->index(true) @@ -31,7 +31,7 @@ 'files' => [ 'label' => I18n::translate('files'), 'icon' => 'image', - 'query' => function (string|null $query = null, int $limit, int $page) { + 'query' => function (string|null $query, int $limit, int $page) { $kirby = App::instance(); $files = $kirby->site() ->index(true) diff --git a/config/areas/users/searches.php b/config/areas/users/searches.php index 6ad3a1fe85..b4e4a0b4fb 100644 --- a/config/areas/users/searches.php +++ b/config/areas/users/searches.php @@ -8,7 +8,7 @@ 'users' => [ 'label' => I18n::translate('users'), 'icon' => 'users', - 'query' => function (string|null $query = null, int $limit, int $page) { + 'query' => function (string|null $query, int $limit, int $page) { $kirby = App::instance(); $users = $kirby->users() ->search($query) diff --git a/src/Cms/Blueprint.php b/src/Cms/Blueprint.php index e9c7dd2d84..ff97590e4f 100644 --- a/src/Cms/Blueprint.php +++ b/src/Cms/Blueprint.php @@ -320,7 +320,7 @@ public static function extend($props): array */ public static function factory( string $name, - string|null $fallback = null, + string|null $fallback, ModelWithContent $model ): static|null { try { diff --git a/src/Cms/Media.php b/src/Cms/Media.php index d210c8bbb3..fe8c8e93b1 100644 --- a/src/Cms/Media.php +++ b/src/Cms/Media.php @@ -27,7 +27,7 @@ class Media * and to copy it to the media folder. */ public static function link( - Page|Site|User|null $model = null, + Page|Site|User|null $model, string $hash, string $filename ): Response|false { diff --git a/src/Toolkit/Str.php b/src/Toolkit/Str.php index c776848709..0a4dde483f 100644 --- a/src/Toolkit/Str.php +++ b/src/Toolkit/Str.php @@ -263,7 +263,7 @@ public static function beforeEnd( * Returns everything between two strings from the first occurrence of a given string */ public static function between( - string|null $string = null, + string|null $string, string $start, string $end ): string { @@ -295,7 +295,7 @@ public static function camelToKebab(string|null $value = null): string * Checks if a str contains another string */ public static function contains( - string|null $string = null, + string|null $string, string $needle, bool $caseInsensitive = false ): bool { @@ -414,7 +414,7 @@ public static function encoding(string $string): string * Checks if a string ends with the passed needle */ public static function endsWith( - string|null $string = null, + string|null $string, string $needle, bool $caseInsensitive = false ): bool { @@ -707,7 +707,7 @@ public static function pool( * @throws \Kirby\Exception\InvalidArgumentException for empty $needle */ public static function position( - string|null $string = null, + string|null $string, string $needle, bool $caseInsensitive = false ): int|false { @@ -1230,7 +1230,7 @@ public static function split( * Checks if a string starts with the passed needle */ public static function startsWith( - string|null $string = null, + string|null $string, string $needle, bool $caseInsensitive = false ): bool { diff --git a/src/Toolkit/V.php b/src/Toolkit/V.php index 1d36255151..5d5ce631f4 100644 --- a/src/Toolkit/V.php +++ b/src/Toolkit/V.php @@ -474,28 +474,28 @@ public static function __callStatic(string $method, array $arguments): bool /** * Checks if the number of characters in the value equals or is below the given maximum */ - 'maxLength' => function (string|null $value = null, $max): bool { + 'maxLength' => function (string|null $value, $max): bool { return Str::length(trim($value)) <= $max; }, /** * Checks if the number of characters in the value equals or is greater than the given minimum */ - 'minLength' => function (string|null $value = null, $min): bool { + 'minLength' => function (string|null $value, $min): bool { return Str::length(trim($value)) >= $min; }, /** * Checks if the number of words in the value equals or is below the given maximum */ - 'maxWords' => function (string|null $value = null, $max): bool { + 'maxWords' => function (string|null $value, $max): bool { return V::max(explode(' ', trim($value)), $max) === true; }, /** * Checks if the number of words in the value equals or is below the given maximum */ - 'minWords' => function (string|null $value = null, $min): bool { + 'minWords' => function (string|null $value, $min): bool { return V::min(explode(' ', trim($value)), $min) === true; }, From 25985aa3c17be9e5905a3c70e8948bd017f23c85 Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Sat, 7 Dec 2024 13:33:15 +0100 Subject: [PATCH 09/12] Try to exclude Psalm from PHP 8.4 CI --- .github/workflows/backend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index b51abc30ea..9b575b04d2 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -122,7 +122,7 @@ jobs: run: phpunit --fail-on-skipped --coverage-clover ${{ github.workspace }}/clover.xml - name: Statically analyze using Psalm - if: always() && steps.finishPrepare.outcome == 'success' + if: always() && steps.finishPrepare.outcome == 'success' && ${{ matrix.php-version != '8.4' }} run: psalm --output-format=github --php-version=${{ matrix.php }} --report=sarif/psalm.sarif --report-show-info=false - name: Upload coverage results to Codecov From dc4aa98ab97ba293dcf8baf757114661c4493dda Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Sat, 7 Dec 2024 13:47:23 +0100 Subject: [PATCH 10/12] Try different PHPUnit version --- .github/workflows/backend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 9b575b04d2..1a378ea31d 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -99,7 +99,7 @@ jobs: extensions: ${{ env.extensions }} ini-values: ${{ env.ini }} coverage: pcov - tools: phpunit:11.4.3, psalm:5.26.1 + tools: phpunit:10.5.38, psalm:5.26.1 - name: Setup problem matchers run: | From e5e574209bea1481fdfbebecac2ed46efc9fad7a Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Sat, 7 Dec 2024 13:56:57 +0100 Subject: [PATCH 11/12] Try once more to exclude Psalm on PHP 8.4 --- .github/workflows/backend.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 1a378ea31d..80f7059dd3 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -122,7 +122,7 @@ jobs: run: phpunit --fail-on-skipped --coverage-clover ${{ github.workspace }}/clover.xml - name: Statically analyze using Psalm - if: always() && steps.finishPrepare.outcome == 'success' && ${{ matrix.php-version != '8.4' }} + if: always() && steps.finishPrepare.outcome == 'success' && matrix.php != '8.4' run: psalm --output-format=github --php-version=${{ matrix.php }} --report=sarif/psalm.sarif --report-show-info=false - name: Upload coverage results to Codecov @@ -139,7 +139,7 @@ jobs: env_vars: PHP - name: Upload code scanning results to GitHub - if: always() && steps.finishPrepare.outcome == 'success' && github.repository == 'getkirby/kirby' + if: always() && steps.finishPrepare.outcome == 'success' && github.repository == 'getkirby/kirby' && matrix.php != '8.4' uses: github/codeql-action/upload-sarif@4a8f20f6b9b5114f354129a1e2f391d75bfd640a # pin@v2 with: sarif_file: sarif From 48242389c4483c2167f398ad2bcfa918151a51b3 Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Sat, 7 Dec 2024 14:17:54 +0100 Subject: [PATCH 12/12] Try adding PHP 8.1 back to CI --- .github/workflows/backend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 80f7059dd3..74d24738cb 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -57,7 +57,7 @@ jobs: timeout-minutes: 5 strategy: matrix: - php: ["8.2", "8.3", "8.4"] + php: ["8.1", "8.2", "8.3", "8.4"] env: extensions: mbstring, ctype, curl, gd, apcu, memcached ini: apc.enabled=1, apc.enable_cli=1, pcov.directory=., "pcov.exclude=\"~(vendor|tests)~\""