Skip to content

Commit 1976cc0

Browse files
committed
differentiate between various types of “use” in error message
1 parent a0365f7 commit 1976cc0

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Rules/Names/UsedNamesRule.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,23 @@ private function findErrorsInUses(array $uses, string $useGroupPrefix, string $l
161161
}
162162
$useAlias = $use->getAlias()->toLowerString();
163163
if (in_array($useAlias, $usedNames[$realUseType][$lowerNamespace] ?? [], true)) {
164+
if ($realUseType === Use_::TYPE_FUNCTION) {
165+
$displayedUseType = 'use function';
166+
$identifierUseType = 'useFunction';
167+
} elseif ($realUseType === Use_::TYPE_CONSTANT) {
168+
$displayedUseType = 'use const';
169+
$identifierUseType = 'useConst';
170+
} else {
171+
$displayedUseType = 'use';
172+
$identifierUseType = 'use';
173+
}
164174
$errors[] = RuleErrorBuilder::message(sprintf(
165-
'Cannot use %s as %s because the name is already in use.',
175+
'Cannot %s %s as %s because the name is already in use.',
176+
$displayedUseType,
166177
$useGroupPrefix !== '' ? $useGroupPrefix . '\\' . $use->name->toString() : $use->name->toString(),
167178
$use->getAlias()->toString(),
168179
))
169-
->identifier('use.nameInUse')
180+
->identifier(sprintf('%s.nameInUse', $identifierUseType))
170181
->line($use->getStartLine())
171182
->nonIgnorable()
172183
->build();

0 commit comments

Comments
 (0)