From 3635758de3b616ec91b0be6e0b37745d688c2401 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Tue, 31 Dec 2024 12:05:54 +0100 Subject: [PATCH] PHP baseline: fix path (#32) * PhpBaselineHandler.php: fix path Add missing slash, because __DIR__ does not have a trailing slash unless it is the root directory, @see https://www.php.net/manual/en/language.constants.magic.php#constant.dir * Fix test --------- Co-authored-by: jmdelehaye --- src/Handler/PhpBaselineHandler.php | 2 +- tests/Rule/data/baselines-php/another.identifier.php | 2 +- tests/Rule/data/baselines-php/missing-identifier.php | 2 +- tests/Rule/data/baselines-php/sample.identifier.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Handler/PhpBaselineHandler.php b/src/Handler/PhpBaselineHandler.php index 3458d97..fc8bfea 100644 --- a/src/Handler/PhpBaselineHandler.php +++ b/src/Handler/PhpBaselineHandler.php @@ -41,7 +41,7 @@ public function encodeBaseline(string $comment, array $errors, string $indent): "\$ignoreErrors[] = [\n{$indent}'message' => %s,\n{$indent}'count' => %d,\n{$indent}'path' => __DIR__ . %s,\n];\n", var_export($error['message'], true), var_export($error['count'], true), - var_export($error['path'], true), + var_export('/' . $error['path'], true), ); } diff --git a/tests/Rule/data/baselines-php/another.identifier.php b/tests/Rule/data/baselines-php/another.identifier.php index 10b1022..b5017fd 100644 --- a/tests/Rule/data/baselines-php/another.identifier.php +++ b/tests/Rule/data/baselines-php/another.identifier.php @@ -6,7 +6,7 @@ $ignoreErrors[] = [ 'message' => '#^Error to escape \'\\#$#', 'count' => 1, - 'path' => __DIR__ . '../app/config.php', + 'path' => __DIR__ . '/../app/config.php', ]; return ['parameters' => ['ignoreErrors' => $ignoreErrors]]; diff --git a/tests/Rule/data/baselines-php/missing-identifier.php b/tests/Rule/data/baselines-php/missing-identifier.php index 567aaec..991b2ca 100644 --- a/tests/Rule/data/baselines-php/missing-identifier.php +++ b/tests/Rule/data/baselines-php/missing-identifier.php @@ -6,7 +6,7 @@ $ignoreErrors[] = [ 'message' => '#^Error 3$#', 'count' => 1, - 'path' => __DIR__ . '../app/index.php', + 'path' => __DIR__ . '/../app/index.php', ]; return ['parameters' => ['ignoreErrors' => $ignoreErrors]]; diff --git a/tests/Rule/data/baselines-php/sample.identifier.php b/tests/Rule/data/baselines-php/sample.identifier.php index e342890..d37c9e6 100644 --- a/tests/Rule/data/baselines-php/sample.identifier.php +++ b/tests/Rule/data/baselines-php/sample.identifier.php @@ -6,7 +6,7 @@ $ignoreErrors[] = [ 'message' => '#^Error simple$#', 'count' => 1, - 'path' => __DIR__ . '../app/file.php', + 'path' => __DIR__ . '/../app/file.php', ]; return ['parameters' => ['ignoreErrors' => $ignoreErrors]];