From 9b07a3e4f6aeb3991463d207cdc95d8d148d155b Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 30 May 2025 16:22:57 +0700 Subject: [PATCH 1/6] Explicitly marking parameters as nullable --- CHANGELOG.md | 2 +- composer.json | 4 ++-- src/Message.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4624f551..b42e041a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2.1.1 under development -- no changes in this release. +- Enh #123: Explicitly marking parameters as nullable (@Tigrov) ## 2.1.0 July 03, 2024 diff --git a/composer.json b/composer.json index dc9a70b2..2e50b012 100644 --- a/composer.json +++ b/composer.json @@ -36,11 +36,11 @@ }, "require-dev": { "maglnet/composer-require-checker": "^4.4", - "phpunit/phpunit": "^9.5", + "phpunit/phpunit": "^9.6", "rector/rector": "^1.2", "roave/infection-static-analysis-plugin": "^1.18", "spatie/phpunit-watcher": "^1.23", - "vimeo/psalm": "^4.30|^5.25" + "vimeo/psalm": "^4.30|^5.25|^6.0" }, "provide": { "psr/log-implementation": "1.0.0" diff --git a/src/Message.php b/src/Message.php index 9a200b20..83e8aa8c 100644 --- a/src/Message.php +++ b/src/Message.php @@ -110,7 +110,7 @@ public function message(): string * * @return mixed The context parameter value. */ - public function context(string $name = null, mixed $default = null): mixed + public function context(?string $name = null, mixed $default = null): mixed { if ($name === null) { return $this->context; From 208ee1bb7dca9b996f194368f00a3863434b7d3f Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 30 May 2025 09:24:44 +0000 Subject: [PATCH 2/6] Apply fixes from StyleCI --- src/Message/CategoryFilter.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Message/CategoryFilter.php b/src/Message/CategoryFilter.php index 1ec8013d..2271a975 100644 --- a/src/Message/CategoryFilter.php +++ b/src/Message/CategoryFilter.php @@ -5,7 +5,6 @@ namespace Yiisoft\Log\Message; use InvalidArgumentException; - use Yiisoft\Log\Message; use function is_string; From 5e786088193a3c9ff25ffe8d5589a3675778d203 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 30 May 2025 16:56:22 +0700 Subject: [PATCH 3/6] Fix psalm --- psalm.xml | 2 ++ src/Message.php | 1 + src/Message/ContextValueExtractor.php | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/psalm.xml b/psalm.xml index 95805489..5fb1e427 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,8 +1,10 @@ Date: Sat, 31 May 2025 10:59:12 +0700 Subject: [PATCH 4/6] Fix empty key --- src/Message/ContextValueExtractor.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Message/ContextValueExtractor.php b/src/Message/ContextValueExtractor.php index 2c3f7283..3fbe8908 100644 --- a/src/Message/ContextValueExtractor.php +++ b/src/Message/ContextValueExtractor.php @@ -16,12 +16,9 @@ public static function extract(array $context, string $key): array { $path = self::parsePath($key); + /** @var string $lastKey */ $lastKey = array_pop($path); - if ($lastKey === null) { - return [false, null]; - } - $array = $context; foreach ($path as $pathItem) { $array = array_key_exists($pathItem, $array) ? $array[$pathItem] : null; @@ -41,7 +38,7 @@ public static function extract(array $context, string $key): array private static function parsePath(string $path): array { if ($path === '') { - return []; + return ['']; } if (!str_contains($path, '.')) { From a7edf9a247c9fcc2a241730605e15c25adf20497 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sat, 31 May 2025 11:06:39 +0700 Subject: [PATCH 5/6] Add line to CHANGELOG.md --- CHANGELOG.md | 3 ++- src/Message/ContextValueExtractor.php | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b42e041a..2a5b42e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## 2.1.1 under development -- Enh #123: Explicitly marking parameters as nullable (@Tigrov) +- Bug #123: Explicitly marking parameters as nullable (@Tigrov) +- Bug #123: Fix `ContextValueExtractor::extract()` with empty key in PHP 8.4 (@Tigrov) ## 2.1.0 July 03, 2024 diff --git a/src/Message/ContextValueExtractor.php b/src/Message/ContextValueExtractor.php index 3fbe8908..6983af57 100644 --- a/src/Message/ContextValueExtractor.php +++ b/src/Message/ContextValueExtractor.php @@ -16,10 +16,9 @@ public static function extract(array $context, string $key): array { $path = self::parsePath($key); - /** @var string $lastKey */ $lastKey = array_pop($path); - $array = $context; + foreach ($path as $pathItem) { $array = array_key_exists($pathItem, $array) ? $array[$pathItem] : null; if (!is_array($array)) { @@ -33,7 +32,7 @@ public static function extract(array $context, string $key): array } /** - * @psalm-return list + * @psalm-return non-empty-list */ private static function parsePath(string $path): array { From 3e1187459068b68224f50973487c1d5742450922 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sat, 31 May 2025 11:14:02 +0700 Subject: [PATCH 6/6] Test PHP 8.4 --- .github/workflows/bc.yml | 2 +- .github/workflows/build.yml | 2 +- .github/workflows/composer-require-checker.yml | 2 +- .github/workflows/mutation.yml | 2 +- .github/workflows/rector.yml | 2 +- .github/workflows/static.yml | 2 +- composer.json | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/bc.yml b/.github/workflows/bc.yml index f8cc5648..0ea4a5c1 100644 --- a/.github/workflows/bc.yml +++ b/.github/workflows/bc.yml @@ -30,4 +30,4 @@ jobs: os: >- ['ubuntu-latest'] php: >- - ['8.0'] + ['8.4'] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e96052e5..68fac01f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,4 +31,4 @@ jobs: os: >- ['ubuntu-latest', 'windows-latest'] php: >- - ['8.0', '8.1', '8.2', '8.3'] + ['8.0', '8.1', '8.2', '8.3', '8.4'] diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml index 5473ec96..632bfd48 100644 --- a/.github/workflows/composer-require-checker.yml +++ b/.github/workflows/composer-require-checker.yml @@ -31,4 +31,4 @@ jobs: os: >- ['ubuntu-latest'] php: >- - ['8.0', '8.1', '8.2', '8.3'] + ['8.0', '8.1', '8.2', '8.3', '8.4'] diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index a6873e2e..a56769ea 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -27,6 +27,6 @@ jobs: os: >- ['ubuntu-latest'] php: >- - ['8.3'] + ['8.4'] secrets: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index 35411d0a..b2294456 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -20,4 +20,4 @@ jobs: os: >- ['ubuntu-latest'] php: >- - ['8.3'] + ['8.4'] diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index aea590ea..27126190 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -30,4 +30,4 @@ jobs: os: >- ['ubuntu-latest'] php: >- - ['8.0', '8.1', '8.2', '8.3'] + ['8.0', '8.1', '8.2', '8.3', '8.4'] diff --git a/composer.json b/composer.json index 2e50b012..23d21c6a 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "require-dev": { "maglnet/composer-require-checker": "^4.4", "phpunit/phpunit": "^9.6", - "rector/rector": "^1.2", + "rector/rector": "^2.0", "roave/infection-static-analysis-plugin": "^1.18", "spatie/phpunit-watcher": "^1.23", "vimeo/psalm": "^4.30|^5.25|^6.0"