From 073e8481bfc01e07934f69a44c40a56911404a75 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 23 Aug 2023 19:56:14 +0700 Subject: [PATCH 1/6] [Php73][Php80] Handle empty long array syntax default value on SensitiveConstantNameRector+AddParamBasedOnParentClassMethodRector --- .../EmptyLongArraySyntaxTest.php | 28 ++++++++++++++++ .../Fixture/empty_long_array.php.inc | 33 +++++++++++++++++++ .../Source/ParentWithEmptyLongArray.php | 12 +++++++ .../config/configured_rule.php | 14 ++++++++ 4 files changed, 87 insertions(+) create mode 100644 tests/Issues/EmptyLongArraySyntax/EmptyLongArraySyntaxTest.php create mode 100644 tests/Issues/EmptyLongArraySyntax/Fixture/empty_long_array.php.inc create mode 100644 tests/Issues/EmptyLongArraySyntax/Source/ParentWithEmptyLongArray.php create mode 100644 tests/Issues/EmptyLongArraySyntax/config/configured_rule.php diff --git a/tests/Issues/EmptyLongArraySyntax/EmptyLongArraySyntaxTest.php b/tests/Issues/EmptyLongArraySyntax/EmptyLongArraySyntaxTest.php new file mode 100644 index 00000000000..706b3d9b9c1 --- /dev/null +++ b/tests/Issues/EmptyLongArraySyntax/EmptyLongArraySyntaxTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Issues/EmptyLongArraySyntax/Fixture/empty_long_array.php.inc b/tests/Issues/EmptyLongArraySyntax/Fixture/empty_long_array.php.inc new file mode 100644 index 00000000000..f269d179b05 --- /dev/null +++ b/tests/Issues/EmptyLongArraySyntax/Fixture/empty_long_array.php.inc @@ -0,0 +1,33 @@ + +----- + diff --git a/tests/Issues/EmptyLongArraySyntax/Source/ParentWithEmptyLongArray.php b/tests/Issues/EmptyLongArraySyntax/Source/ParentWithEmptyLongArray.php new file mode 100644 index 00000000000..64e93c450d8 --- /dev/null +++ b/tests/Issues/EmptyLongArraySyntax/Source/ParentWithEmptyLongArray.php @@ -0,0 +1,12 @@ +rules([ + SensitiveConstantNameRector::class, + AddParamBasedOnParentClassMethodRector::class, + ]); +}; From 55906b90f2af49340b000b9cc2173f81c278978e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 23 Aug 2023 19:58:47 +0700 Subject: [PATCH 2/6] update fixture --- .../EmptyLongArraySyntax/Fixture/empty_long_array.php.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Issues/EmptyLongArraySyntax/Fixture/empty_long_array.php.inc b/tests/Issues/EmptyLongArraySyntax/Fixture/empty_long_array.php.inc index f269d179b05..8ea4e282189 100644 --- a/tests/Issues/EmptyLongArraySyntax/Fixture/empty_long_array.php.inc +++ b/tests/Issues/EmptyLongArraySyntax/Fixture/empty_long_array.php.inc @@ -25,7 +25,7 @@ use Rector\Core\Tests\Issues\EmptyLongArraySyntax\Source\ParentWithEmptyLongArra final class EmptyLongArray extends ParentWithEmptyLongArray { - public function run() + public function run($default = array()) { } } From 6e59e4bcc02029cb24719154ec65ad0ad36c3e86 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 23 Aug 2023 20:08:47 +0700 Subject: [PATCH 3/6] Fix --- rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php | 1 + 1 file changed, 1 insertion(+) diff --git a/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php b/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php index 8fa27e47277..22d419272d0 100644 --- a/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php +++ b/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php @@ -84,6 +84,7 @@ final class SensitiveConstantNameRector extends AbstractScopeAwareRector impleme 'TRUE', 'FALSE', 'NULL', + 'ARRAY()' ]; public function __construct( From 58e9a3674bbaa62e0d598318354d3bef0b6b24be Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 23 Aug 2023 20:10:53 +0700 Subject: [PATCH 4/6] Fix --- .../Php73/Rector/ConstFetch/SensitiveConstantNameRector.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php b/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php index 22d419272d0..c426f14768e 100644 --- a/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php +++ b/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php @@ -84,7 +84,6 @@ final class SensitiveConstantNameRector extends AbstractScopeAwareRector impleme 'TRUE', 'FALSE', 'NULL', - 'ARRAY()' ]; public function __construct( @@ -158,6 +157,10 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node return null; } + if (str_contains($uppercasedConstantName, '(')) { + return null; + } + $node->name = new FullyQualified($uppercasedConstantName); return $node; From b8f06743b82ad79018190aeeee7487663e0da874 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 23 Aug 2023 20:15:41 +0700 Subject: [PATCH 5/6] fix --- .../Php73/Rector/ConstFetch/SensitiveConstantNameRector.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php b/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php index c426f14768e..a8bafeb97bd 100644 --- a/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php +++ b/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php @@ -153,11 +153,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node return null; } - if (str_contains($uppercasedConstantName, '\\')) { - return null; - } - - if (str_contains($uppercasedConstantName, '(')) { + if (str_contains($uppercasedConstantName, '\\') || str_contains($uppercasedConstantName, '(') || str_contains($uppercasedConstantName, "'") || str_contains($uppercasedConstantName, '"')) { return null; } From 6aa1836e2a8d097a817658f7480c02ed1f62b42f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 23 Aug 2023 20:18:02 +0700 Subject: [PATCH 6/6] fix --- .../Php73/Rector/ConstFetch/SensitiveConstantNameRector.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php b/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php index a8bafeb97bd..5cb1ccf9d21 100644 --- a/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php +++ b/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php @@ -153,7 +153,11 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node return null; } - if (str_contains($uppercasedConstantName, '\\') || str_contains($uppercasedConstantName, '(') || str_contains($uppercasedConstantName, "'") || str_contains($uppercasedConstantName, '"')) { + if ( + str_contains($uppercasedConstantName, '\\') + || str_contains($uppercasedConstantName, '(') + || str_contains($uppercasedConstantName, "'") + ) { return null; }