Skip to content

Commit 3c3757d

Browse files
committed
Another message adjustment
1 parent 8ff89ed commit 3c3757d

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/Rules/ClassNameUsageLocation.php

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ public function createMessage(string $part): string
117117
{
118118
switch ($this->value) {
119119
case self::TRAIT_USE:
120+
if ($this->getCurrentClassName() !== null) {
121+
return sprintf('Usage of %s in class %s.', $part, $this->getCurrentClassName());
122+
}
120123
return sprintf('Usage of %s.', $part);
121124
case self::STATIC_PROPERTY_ACCESS:
122125
$property = $this->getProperty();

src/Rules/Classes/ExistingClassInTraitUseRule.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,20 @@ public function getNodeType(): string
3535

3636
public function processNode(Node $node, Scope $scope): array
3737
{
38-
$messages = $this->classCheck->checkClassNames(
39-
$scope,
40-
array_map(static fn (Node\Name $traitName): ClassNameNodePair => new ClassNameNodePair((string) $traitName, $traitName), $node->traits),
41-
ClassNameUsageLocation::from(ClassNameUsageLocation::TRAIT_USE),
42-
);
43-
4438
if (!$scope->isInClass()) {
4539
throw new ShouldNotHappenException();
4640
}
4741

4842
$classReflection = $scope->getClassReflection();
43+
44+
$messages = $this->classCheck->checkClassNames(
45+
$scope,
46+
array_map(static fn (Node\Name $traitName): ClassNameNodePair => new ClassNameNodePair((string) $traitName, $traitName), $node->traits),
47+
ClassNameUsageLocation::from(ClassNameUsageLocation::TRAIT_USE, [
48+
'currentClassName' => $classReflection->isAnonymous() ? null : $classReflection->getName(),
49+
]),
50+
);
51+
4952
if ($classReflection->isInterface()) {
5053
if (!$scope->isInTrait()) {
5154
foreach ($node->traits as $trait) {

0 commit comments

Comments
 (0)