-
Notifications
You must be signed in to change notification settings - Fork 18
Description
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 abbreviatedExpected 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- 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