FullNamesFixer: false positive on short but valid variable names
Problem
The Paysera/php_basic_code_style_full_names rule incorrectly flags short but semantically complete variable names like $id when used with type hints such as Uuid $id.
The variable $id is not an abbreviation - it is the full, correct name for an identifier. The rule treats it as abbreviated because its length (excluding $) is less than the hardcoded MINIMUM_NAMESPACE_CHARACTER_LENGTH = 4.
Current behavior
function findById(Uuid $id) // flagged as abbreviated
Expected behavior
$id should not be flagged when it is a known, complete word.
Changes required
1. Add ignore_words configuration option
Allow users to configure a list of known words that should never be considered abbreviated:
$fixer->configure([
'ignore_words' => ['id', 'db', 'ip', 'url', 'uri', 'dto'],
]);
2. Make MINIMUM_NAMESPACE_CHARACTER_LENGTH configurable
The constant MINIMUM_NAMESPACE_CHARACTER_LENGTH is currently hardcoded to 4 (line 17 in FullNamesFixer.php). This should become a configuration option:
$fixer->configure([
'min_length' => 4, // default
]);
3. Update isVariableTruncated to exclude known words
The isVariableTruncated method (lines 140-153) should check against the ignore_words list before determining that a variable is truncated.
Relevant code
src/Fixer/PhpBasic/CodeStyle/FullNamesFixer.php:17 - hardcoded MINIMUM_NAMESPACE_CHARACTER_LENGTH = 4
src/Fixer/PhpBasic/CodeStyle/FullNamesFixer.php:92-93 - length check logic (OR with truncation check)
src/Fixer/PhpBasic/CodeStyle/FullNamesFixer.php:140-153 - isVariableTruncated method
FullNamesFixer: false positive on short but valid variable names
Problem
The
Paysera/php_basic_code_style_full_namesrule incorrectly flags short but semantically complete variable names like$idwhen used with type hints such asUuid $id.The variable
$idis not an abbreviation - it is the full, correct name for an identifier. The rule treats it as abbreviated because its length (excluding$) is less than the hardcodedMINIMUM_NAMESPACE_CHARACTER_LENGTH = 4.Current behavior
Expected behavior
$idshould not be flagged when it is a known, complete word.Changes required
1. Add
ignore_wordsconfiguration optionAllow users to configure a list of known words that should never be considered abbreviated:
2. Make
MINIMUM_NAMESPACE_CHARACTER_LENGTHconfigurableThe constant
MINIMUM_NAMESPACE_CHARACTER_LENGTHis currently hardcoded to4(line 17 inFullNamesFixer.php). This should become a configuration option:3. Update
isVariableTruncatedto exclude known wordsThe
isVariableTruncatedmethod (lines 140-153) should check against theignore_wordslist before determining that a variable is truncated.Relevant code
src/Fixer/PhpBasic/CodeStyle/FullNamesFixer.php:17- hardcodedMINIMUM_NAMESPACE_CHARACTER_LENGTH = 4src/Fixer/PhpBasic/CodeStyle/FullNamesFixer.php:92-93- length check logic (OR with truncation check)src/Fixer/PhpBasic/CodeStyle/FullNamesFixer.php:140-153-isVariableTruncatedmethod