improve SensitiveConstantNameRector code

This commit is contained in:
Tomas Votruba 2019-02-21 12:05:20 +01:00
parent ef6bd19e70
commit c93b2db8d8

View File

@ -112,23 +112,29 @@ CODE_SAMPLE
*/ */
public function refactor(Node $node): ?Node public function refactor(Node $node): ?Node
{ {
// is system constant? $constantName = $this->getName($node);
if (in_array(strtoupper((string) $node->name), $this->phpReservedConstants, true)) { if ($constantName === null) {
return null; return null;
} }
$currentConstantName = (string) $node->name; $uppercasedConstantName = strtoupper($constantName);
if (\defined($currentConstantName)) { // is system constant?
return null; 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 // is uppercase, all good
if ($currentConstantName === strtoupper($currentConstantName)) { if ($constantName === $uppercasedConstantName) {
return null; return null;
} }
$node->name = new FullyQualified(strtoupper($currentConstantName)); $node->name = new FullyQualified($uppercasedConstantName);
return $node; return $node;
} }