From d1626c1098bc0942095efeb36e4a01f4cbc8ba64 Mon Sep 17 00:00:00 2001 From: Arshid Date: Sun, 7 Sep 2025 13:01:03 +0530 Subject: [PATCH 1/2] Replace with http_get_last_response_headers() call --- .../Fixture/http_response.php.inc | 20 ++++ .../Fixture/skip_http_response.php.inc | 10 ++ .../Fixture/skip_http_response_assing.php.inc | 9 ++ .../Fixture/skip_http_response_null.php.inc | 10 ++ .../ReplaceHttpResponseHeaderRectorTest.php | 28 ++++++ .../config/configured_rule.php | 13 +++ .../ReplaceHttpResponseHeaderRector.php | 91 +++++++++++++++++++ 7 files changed, 181 insertions(+) create mode 100644 rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/http_response.php.inc create mode 100644 rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/skip_http_response.php.inc create mode 100644 rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/skip_http_response_assing.php.inc create mode 100644 rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/skip_http_response_null.php.inc create mode 100644 rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/ReplaceHttpResponseHeaderRectorTest.php create mode 100644 rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/config/configured_rule.php create mode 100644 rules/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector.php diff --git a/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/http_response.php.inc b/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/http_response.php.inc new file mode 100644 index 00000000000..4cefcd7ff7a --- /dev/null +++ b/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/http_response.php.inc @@ -0,0 +1,20 @@ + +----- + diff --git a/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/skip_http_response.php.inc b/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/skip_http_response.php.inc new file mode 100644 index 00000000000..11954c8c8b8 --- /dev/null +++ b/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/skip_http_response.php.inc @@ -0,0 +1,10 @@ + diff --git a/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/skip_http_response_assing.php.inc b/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/skip_http_response_assing.php.inc new file mode 100644 index 00000000000..fa32a22a0fb --- /dev/null +++ b/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/skip_http_response_assing.php.inc @@ -0,0 +1,9 @@ + diff --git a/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/skip_http_response_null.php.inc b/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/skip_http_response_null.php.inc new file mode 100644 index 00000000000..1d0b4da8f5b --- /dev/null +++ b/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/Fixture/skip_http_response_null.php.inc @@ -0,0 +1,10 @@ + diff --git a/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/ReplaceHttpResponseHeaderRectorTest.php b/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/ReplaceHttpResponseHeaderRectorTest.php new file mode 100644 index 00000000000..73a2cbe6e64 --- /dev/null +++ b/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/ReplaceHttpResponseHeaderRectorTest.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/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/config/configured_rule.php b/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/config/configured_rule.php new file mode 100644 index 00000000000..e2b467b501a --- /dev/null +++ b/rules-tests/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector/config/configured_rule.php @@ -0,0 +1,13 @@ +rule(ReplaceHttpResponseHeaderRector::class); + + $rectorConfig->phpVersion(PhpVersion::PHP_85); +}; diff --git a/rules/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector.php b/rules/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector.php new file mode 100644 index 00000000000..53b74c253cc --- /dev/null +++ b/rules/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector.php @@ -0,0 +1,91 @@ +> + */ + public function getNodeTypes(): array + { + return [Expression::class]; + } + + /** + * @param Variable $node + */ + public function refactor(Node $node): ?Array + { + $variables = $this->betterNodeFinder->findInstanceOf($node, Variable::class); + + foreach ($variables as $var) { + if( $var->getAttribute(AttributeKey::IS_BEING_ASSIGNED)){ + return null; + } + if ($this->getName($var) === 'http_response_header') { + + $assign = new Expression( + new Assign( + new Variable('http_response_header'), + new FuncCall(new Name('http_get_last_response_headers')) + ) + ); + return [$assign, $node]; + } + } + + return null; + } +} From 9f54b33e2d042676783aadea49ebd3505eabded2 Mon Sep 17 00:00:00 2001 From: Arshid Date: Sun, 7 Sep 2025 13:08:16 +0530 Subject: [PATCH 2/2] Replace with http_get_last_response_headers() call --- config/set/php85.php | 2 ++ .../Rector/Expression/ReplaceHttpResponseHeaderRector.php | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/config/set/php85.php b/config/set/php85.php index 19715d7a0c2..c1b9736af6f 100644 --- a/config/set/php85.php +++ b/config/set/php85.php @@ -10,6 +10,7 @@ use Rector\Php85\Rector\ArrayDimFetch\ArrayFirstLastRector; use Rector\Php85\Rector\ClassMethod\NullDebugInfoReturnRector; use Rector\Php85\Rector\Const_\DeprecatedAnnotationToDeprecatedAttributeRector; +use Rector\Php85\Rector\Expression\ReplaceHttpResponseHeaderRector; use Rector\Php85\Rector\FuncCall\ArrayKeyExistsNullToEmptyStringRector; use Rector\Php85\Rector\FuncCall\ChrArgModuloRector; use Rector\Php85\Rector\FuncCall\OrdSingleByteRector; @@ -39,6 +40,7 @@ ArrayKeyExistsNullToEmptyStringRector::class, ChrArgModuloRector::class, OrdSingleByteRector::class, + ReplaceHttpResponseHeaderRector::class, ] ); diff --git a/rules/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector.php b/rules/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector.php index 53b74c253cc..ab768ca18c4 100644 --- a/rules/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector.php +++ b/rules/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector.php @@ -64,7 +64,8 @@ public function getNodeTypes(): array } /** - * @param Variable $node + * @param Node $node + * @return array */ public function refactor(Node $node): ?Array {