Uppercase Keyword
ID |
php.keywords_case |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Code Smell |
Language |
Php |
Tags |
code_smell, naming |
Description
Reports PHP keywords — and the constants true, false and null — written in anything other
than lower case, such as IF, Function or TRUE. The recognised keyword set is configurable
through the keywords property.
Rationale
PHP is case-insensitive for its keywords and for the true, false and null constants, so
IF, If and if all compile. Mixing cases hurts readability: the eye uses the consistent lower
case of keywords to separate language scaffolding from the program’s own identifiers, and that cue
is lost when the casing wanders. The community style guides require keywords and these constants
to be written in lower case.
<?php
class Widget
{
public function render(int $n): string
{
IF ($n > 0) { // FLAW - keyword IF should be lower case
return "positive"; // OK - keyword is already lower case
}
return "non-positive";
}
}
Remediation
Rewrite the flagged keyword in lower case (IF becomes if, Function becomes function,
TRUE becomes true).