diff --git a/build/target-repository/docs/rector_rules_overview.md b/build/target-repository/docs/rector_rules_overview.md index 28db6ebe9ba..e460902499e 100644 --- a/build/target-repository/docs/rector_rules_overview.md +++ b/build/target-repository/docs/rector_rules_overview.md @@ -1,4 +1,4 @@ -# 381 Rules Overview +# 382 Rules Overview
@@ -38,7 +38,7 @@ - [Php73](#php73) (9) -- [Php74](#php74) (13) +- [Php74](#php74) (14) - [Php80](#php80) (16) @@ -4730,6 +4730,19 @@ Change `filter_var()` with slash escaping to `addslashes()`
+### HebrevcToNl2brHebrevRector + +Change hebrevc($str) to nl2br(hebrev($str)) + +- class: [`Rector\Php74\Rector\FuncCall\HebrevcToNl2brHebrevRector`](../rules/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector.php) + +```diff +-hebrevc($str); ++nl2br(hebrev($str)); +``` + +
+ ### MbStrrposEncodingArgumentPositionRector Change `mb_strrpos()` encoding argument position diff --git a/config/set/php74.php b/config/set/php74.php index 60fde143e2b..0cbfe7404dc 100644 --- a/config/set/php74.php +++ b/config/set/php74.php @@ -9,6 +9,7 @@ use Rector\Php74\Rector\Double\RealToFloatTypeCastRector; use Rector\Php74\Rector\FuncCall\ArrayKeyExistsOnPropertyRector; use Rector\Php74\Rector\FuncCall\FilterVarToAddSlashesRector; +use Rector\Php74\Rector\FuncCall\HebrevcToNl2brHebrevRector; use Rector\Php74\Rector\FuncCall\MbStrrposEncodingArgumentPositionRector; use Rector\Php74\Rector\FuncCall\MoneyFormatToNumberFormatRector; use Rector\Php74\Rector\FuncCall\RestoreIncludePathToIniRestoreRector; @@ -23,7 +24,6 @@ #the_real_type # https://wiki.php.net/rfc/deprecations_php_7_4 'is_real' => 'is_float', - //'hebrevc' => ['nl2br', 'hebrev'], ]); $rectorConfig->rules([ @@ -39,5 +39,6 @@ MoneyFormatToNumberFormatRector::class, ParenthesizeNestedTernaryRector::class, RestoreIncludePathToIniRestoreRector::class, + HebrevcToNl2brHebrevRector::class, ]); }; diff --git a/rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/Fixture/fixture.php.inc b/rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/Fixture/fixture.php.inc new file mode 100644 index 00000000000..948783ba763 --- /dev/null +++ b/rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/Fixture/fixture.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/Fixture/skip_first_class_callable.php.inc b/rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/Fixture/skip_first_class_callable.php.inc new file mode 100644 index 00000000000..e01531e7fc2 --- /dev/null +++ b/rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/Fixture/skip_first_class_callable.php.inc @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/Fixture/skip_other_func_call.php.inc b/rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/Fixture/skip_other_func_call.php.inc new file mode 100644 index 00000000000..c96e11a7b97 --- /dev/null +++ b/rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/Fixture/skip_other_func_call.php.inc @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/HebrevcToNl2brHebrevRectorTest.php b/rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/HebrevcToNl2brHebrevRectorTest.php new file mode 100644 index 00000000000..a6a9729a02d --- /dev/null +++ b/rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/HebrevcToNl2brHebrevRectorTest.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/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/config/configured_rule.php b/rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/config/configured_rule.php new file mode 100644 index 00000000000..4ce16ba8ed8 --- /dev/null +++ b/rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/config/configured_rule.php @@ -0,0 +1,9 @@ +withRules([HebrevcToNl2brHebrevRector::class]); diff --git a/rules/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector.php b/rules/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector.php new file mode 100644 index 00000000000..65ffdcb93b8 --- /dev/null +++ b/rules/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector.php @@ -0,0 +1,75 @@ +> + */ + public function getNodeTypes(): array + { + return [FuncCall::class]; + } + + /** + * @param FuncCall $node + */ + public function refactor(Node $node): ?FuncCall + { + if (! $this->isName($node, 'hebrevc')) { + return null; + } + + if ($node->isFirstClassCallable()) { + return null; + } + + $node->name = new Name('hebrev'); + return new FuncCall( + new Name('nl2br'), + [ + new Arg($node) + ] + ); + } +} diff --git a/src/ValueObject/PhpVersionFeature.php b/src/ValueObject/PhpVersionFeature.php index 938a3775ecf..86de5ba52f7 100644 --- a/src/ValueObject/PhpVersionFeature.php +++ b/src/ValueObject/PhpVersionFeature.php @@ -419,6 +419,11 @@ final class PhpVersionFeature */ public const DEPRECATE_RESTORE_INCLUDE_PATH = PhpVersion::PHP_74; + /** + * @var int + */ + public const DEPRECATE_HEBREVC = PhpVersion::PHP_74; + /** * @var int */