mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
improve SensitiveConstantNameRector code
This commit is contained in:
parent
ef6bd19e70
commit
c93b2db8d8
@ -112,23 +112,29 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
// is system constant?
|
||||
if (in_array(strtoupper((string) $node->name), $this->phpReservedConstants, true)) {
|
||||
$constantName = $this->getName($node);
|
||||
if ($constantName === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$currentConstantName = (string) $node->name;
|
||||
$uppercasedConstantName = strtoupper($constantName);
|
||||
|
||||
if (\defined($currentConstantName)) {
|
||||
return null;
|
||||
// is system constant?
|
||||
if (in_array($uppercasedConstantName, $this->phpReservedConstants, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// constant is defined in current lower/upper case
|
||||
if (defined($constantName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// is uppercase, all good
|
||||
if ($currentConstantName === strtoupper($currentConstantName)) {
|
||||
if ($constantName === $uppercasedConstantName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$node->name = new FullyQualified(strtoupper($currentConstantName));
|
||||
$node->name = new FullyQualified($uppercasedConstantName);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user