-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathAddLiteralSeparatorToNumberRector.php
More file actions
99 lines (90 loc) · 2.63 KB
/
AddLiteralSeparatorToNumberRector.php
File metadata and controls
99 lines (90 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
declare(strict_types=1);
namespace Rector\Php74\Rector\LNumber;
use PhpParser\Node;
use PhpParser\Node\Scalar\Float_;
use PhpParser\Node\Scalar\Int_;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Exception\ShouldNotHappenException;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* Taking the most generic use case to the account: https://wiki.php.net/rfc/numeric_literal_separator#should_it_be_the_role_of_an_ide_to_group_digits
* The final check should be done manually
*
* @deprecated as opinionated and group size depends on context. Cannot be automated. Use manually where needed instead.
*/
final class AddLiteralSeparatorToNumberRector extends AbstractRector implements MinPhpVersionInterface, ConfigurableRectorInterface, DeprecatedInterface
{
/**
* @api
* @var string
*/
public const LIMIT_VALUE = 'limit_value';
/**
* @param array<string, mixed> $configuration
*/
public function configure(array $configuration): void
{
}
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Add "_" as thousands separator in numbers for higher or equals to limitValue config',
[
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
$int = 500000;
$float = 1000500.001;
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
$int = 500_000;
$float = 1_000_500.001;
}
}
CODE_SAMPLE
,
[
self::LIMIT_VALUE => 1_000_000,
]
),
]
);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
return [Int_::class, Float_::class];
}
/**
* @param Int_|Float_ $node
*/
public function refactor(Node $node): ?Node
{
throw new ShouldNotHappenException(sprintf(
'"%s" is deprecated as opinionated and group size depends on context. Cannot be automated. Use manually where needed instead',
self::class
));
}
public function provideMinPhpVersion(): int
{
return PhpVersionFeature::LITERAL_SEPARATOR;
}
}