-
-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Php74] Add HebrevcToNl2brHebrevRector (#5977)
* [Php74] Add HebrevcToNl2brHebrevRector * regenerate doc * [ci-review] Rector Rectify * fix constt * Fix @see test --------- Co-authored-by: GitHub Action <actions@github.com>
- Loading branch information
1 parent
e6775f0
commit 9678a2c
Showing
9 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/Fixture/fixture.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php74\Rector\FuncCall\HebrevcToNl2brHebrevRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public function run($str) | ||
{ | ||
hebrevc($str); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php74\Rector\FuncCall\HebrevcToNl2brHebrevRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public function run($str) | ||
{ | ||
nl2br(hebrev($str)); | ||
} | ||
} | ||
|
||
?> |
13 changes: 13 additions & 0 deletions
13
...hp74/Rector/FuncCall/HebrevcToNl2brHebrevRector/Fixture/skip_first_class_callable.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php74\Rector\FuncCall\HebrevcToNl2brHebrevRector\Fixture; | ||
|
||
final class SkipFirstClassCallable | ||
{ | ||
public function run() | ||
{ | ||
return hebrevc(...); | ||
} | ||
} | ||
|
||
?> |
13 changes: 13 additions & 0 deletions
13
...sts/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/Fixture/skip_other_func_call.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php74\Rector\FuncCall\HebrevcToNl2brHebrevRector\Fixture; | ||
|
||
final class SkipOtherFuncCall | ||
{ | ||
public function run($value) | ||
{ | ||
return strlen($value); | ||
} | ||
} | ||
|
||
?> |
28 changes: 28 additions & 0 deletions
28
...tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/HebrevcToNl2brHebrevRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Php74\Rector\FuncCall\HebrevcToNl2brHebrevRector; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class HebrevcToNl2brHebrevRectorTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
rules-tests/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector/config/configured_rule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Php74\Rector\FuncCall\HebrevcToNl2brHebrevRector; | ||
|
||
return RectorConfig::configure() | ||
->withRules([HebrevcToNl2brHebrevRector::class]); |
75 changes: 75 additions & 0 deletions
75
rules/Php74/Rector/FuncCall/HebrevcToNl2brHebrevRector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Php74\Rector\FuncCall; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Arg; | ||
use PhpParser\Node\Expr\FuncCall; | ||
use PhpParser\Node\Name; | ||
use Rector\Rector\AbstractRector; | ||
use Rector\ValueObject\PhpVersionFeature; | ||
use Rector\VersionBonding\Contract\MinPhpVersionInterface; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
/** | ||
* @changelog https://www.php.net/manual/en/migration74.deprecated.php#migration74.deprecated.core.hebrevc | ||
* @see \Rector\Tests\Php74\Rector\FuncCall\HebrevcToNl2brHebrevRector\HebrevcToNl2brHebrevRectorTest | ||
*/ | ||
final class HebrevcToNl2brHebrevRector extends AbstractRector implements MinPhpVersionInterface | ||
{ | ||
public function provideMinPhpVersion(): int | ||
{ | ||
return PhpVersionFeature::DEPRECATE_HEBREVC; | ||
} | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return new RuleDefinition( | ||
'Change hebrevc($str) to nl2br(hebrev($str))', | ||
[ | ||
new CodeSample( | ||
<<<'CODE_SAMPLE' | ||
hebrevc($str); | ||
CODE_SAMPLE | ||
, | ||
<<<'CODE_SAMPLE' | ||
nl2br(hebrev($str)); | ||
CODE_SAMPLE | ||
), | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* @return array<class-string<Node>> | ||
*/ | ||
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) | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters