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-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..ab768ca18c4 --- /dev/null +++ b/rules/Php85/Rector/Expression/ReplaceHttpResponseHeaderRector.php @@ -0,0 +1,92 @@ +> + */ + public function getNodeTypes(): array + { + return [Expression::class]; + } + + /** + * @param Node $node + * @return array + */ + 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; + } +}