1.2.257. Could Be Enumeration¶
This rule detects a potential enumeration. When a property is only and ever assigned a finite number of literals, it may be turned into an enumeration. Currently, the analysis focuses on properties that may have 2 or more values (parameter minElements). The property should only be assigned literals, or constants.
<?php
class x {
private $p = 0;
function foo() {
if ($this->p === 0) {
$this->p = 1;
} else {
$this->p = 0;
}
}
}
?>
Name |
Default |
Type |
Description |
minElements |
2 |
integer |
Minimal number of elements to consider that a property may be an enumeration. |
1.2.257.1. Specs¶
Short name |
Enums/CouldBeEnum |
Rulesets |
|
Exakat since |
2.4.4 |
PHP Version |
8.1 |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Medium |
Available in |