From 19535a2fd7563c98b06b64e0e40cf3ec2e8054f8 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Tue, 3 Jun 2025 13:34:15 +0300 Subject: [PATCH 1/3] Bump dev deps --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 23d21c6a..2753f7e0 100644 --- a/composer.json +++ b/composer.json @@ -31,16 +31,16 @@ ], "require": { "php": "^8.0", - "psr/log": "^2.0|^3.0", + "psr/log": "^2.0 || ^3.0", "yiisoft/var-dumper": "^1.0" }, "require-dev": { "maglnet/composer-require-checker": "^4.4", - "phpunit/phpunit": "^9.6", - "rector/rector": "^2.0", - "roave/infection-static-analysis-plugin": "^1.18", - "spatie/phpunit-watcher": "^1.23", - "vimeo/psalm": "^4.30|^5.25|^6.0" + "phpunit/phpunit": "^9.6.23", + "rector/rector": "^2.0.17", + "roave/infection-static-analysis-plugin": "^1.25", + "spatie/phpunit-watcher": "^1.23.6", + "vimeo/psalm": "^4.30 || ^5.26.1 || ^6.12" }, "provide": { "psr/log-implementation": "1.0.0" From e212395415444fa1b432238f8cc712c016cdaf58 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Tue, 3 Jun 2025 13:35:29 +0300 Subject: [PATCH 2/3] improve rector --- .github/workflows/rector.yml | 3 ++- rector.php | 23 ++++++++--------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index b2294456..5d6931d5 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -1,5 +1,5 @@ on: - pull_request: + pull_request_target: paths-ignore: - 'docs/**' - 'README.md' @@ -17,6 +17,7 @@ jobs: secrets: token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} with: + repository: ${{ github.event.pull_request.head.repo.full_name }} os: >- ['ubuntu-latest'] php: >- diff --git a/rector.php b/rector.php index f55daaed..c2226bf1 100644 --- a/rector.php +++ b/rector.php @@ -5,23 +5,16 @@ use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; -use Rector\Set\ValueObject\LevelSetList; -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->paths([ +return RectorConfig::configure() + ->withPaths([ __DIR__ . '/src', __DIR__ . '/tests', - ]); - - // register a single rule - $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); - - // define sets of rules - $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_80, - ]); - - $rectorConfig->skip([ + ]) + ->withPhpSets(php80: true) + ->withRules([ + InlineConstructorDefaultToPropertyRector::class, + ]) + ->withSkip([ ClosureToArrowFunctionRector::class, ]); -}; From 12acd8f92ee117e2559ec28597237395ff503f9f Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Tue, 3 Jun 2025 13:47:41 +0300 Subject: [PATCH 3/3] refactor `ContextValueExtractor` --- CHANGELOG.md | 2 +- src/Message/ContextValueExtractor.php | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a5b42e9..0143f988 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## 2.1.1 under development - Bug #123: Explicitly marking parameters as nullable (@Tigrov) -- Bug #123: Fix `ContextValueExtractor::extract()` with empty key in PHP 8.4 (@Tigrov) +- Enh #123, #124: Minor refactor internal class `ContextValueExtractor` (@Tigrov, @vjik) ## 2.1.0 July 03, 2024 diff --git a/src/Message/ContextValueExtractor.php b/src/Message/ContextValueExtractor.php index 6983af57..5e50965d 100644 --- a/src/Message/ContextValueExtractor.php +++ b/src/Message/ContextValueExtractor.php @@ -4,6 +4,12 @@ namespace Yiisoft\Log\Message; +use function array_key_exists; +use function count; +use function is_array; +use function sprintf; +use function strlen; + /** * @internal */ @@ -20,7 +26,7 @@ public static function extract(array $context, string $key): array $array = $context; foreach ($path as $pathItem) { - $array = array_key_exists($pathItem, $array) ? $array[$pathItem] : null; + $array = $array[$pathItem] ?? null; if (!is_array($array)) { return [false, null]; }