Inclusive Variable
ID |
php.inclusive_variable |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Code Smell |
Language |
Php |
Tags |
code_smell, inclusive |
Description
Reports a variable or class property whose name contains a non-inclusive term such as
blacklist, whitelist, master or slave. The check is a case-insensitive substring test,
so names like $whitelist or $masterKey are flagged. Each name is reported once, where it is
introduced: a parameter, a class property, an assignment target or a foreach loop variable.
Rationale
Variable and property names appear throughout a file and in any output that dumps state. Terms like master/slave or whitelist/blacklist carry exclusionary connotations and have clear neutral replacements (allow/deny, primary/replica) that lose no meaning. Choosing inclusive names keeps the codebase welcoming to all contributors.
<?php
$whitelist = []; // FLAW - "whitelist" is non-inclusive
$masterKey = ''; // FLAW - "master" is non-inclusive
$allowList = []; // OK - neutral replacement
$primaryKey = ''; // OK - neutral replacement
Remediation
Rename the variable or property to an inclusive equivalent: whitelist becomes allowList,
blacklist becomes denyList, master/slave become primary/replica. Use an IDE rename
refactoring so all references update consistently.