Skip to content

Commit 9c81454

Browse files
committed
[compat] Add SymplifyQuoteEscapeRector deprecated rule for BC layer
1 parent ca6cf9c commit 9c81454

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\CodingStyle\Rector\String_;
6+
7+
use PhpParser\Node;
8+
use PhpParser\Node\Scalar\String_;
9+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
10+
use Rector\Exception\ShouldNotHappenException;
11+
use Rector\Rector\AbstractRector;
12+
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
13+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
14+
15+
/***
16+
* @deprecated Renamed to \Rector\CodingStyle\Rector\String_\SimplifyQuoteEscapeRector
17+
*/
18+
final class SymplifyQuoteEscapeRector extends AbstractRector implements DeprecatedInterface
19+
{
20+
public function getRuleDefinition(): RuleDefinition
21+
{
22+
return new RuleDefinition(
23+
'Prefer quote that are not inside the string',
24+
[
25+
new CodeSample(
26+
<<<'CODE_SAMPLE'
27+
class SomeClass
28+
{
29+
public function run()
30+
{
31+
$name = "\" Tom";
32+
$name = '\' Sara';
33+
}
34+
}
35+
CODE_SAMPLE
36+
,
37+
<<<'CODE_SAMPLE'
38+
class SomeClass
39+
{
40+
public function run()
41+
{
42+
$name = '" Tom';
43+
$name = "' Sara";
44+
}
45+
}
46+
CODE_SAMPLE
47+
),
48+
]
49+
);
50+
}
51+
52+
/**
53+
* @return array<class-string<Node>>
54+
*/
55+
public function getNodeTypes(): array
56+
{
57+
return [String_::class];
58+
}
59+
60+
/**
61+
* @param String_ $node
62+
*/
63+
public function refactor(Node $node): ?String_
64+
{
65+
throw new ShouldNotHappenException(sprintf(
66+
'%s is deprecated and renamed to "%s". Use it instead.',
67+
self::class,
68+
SimplifyQuoteEscapeRector::class
69+
));
70+
}
71+
}

0 commit comments

Comments
 (0)