Skip to content

Commit 9667b8e

Browse files
committed
Add class name to message
1 parent e1e9a63 commit 9667b8e

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/Rules/Classes/ClassConstantRule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public function processNode(Node $node, Scope $scope): array
7676
$type = $typeResult->getType();
7777

7878
if (!$type->isString()->yes()) {
79-
$errors[] = RuleErrorBuilder::message(sprintf('Cannot fetch class constant with a non-stringable type %s.', $nameType->describe(VerbosityLevel::precise())))
79+
$className = $scope->getClassReflection()->getDisplayName();
80+
$errors[] = RuleErrorBuilder::message(sprintf('Cannot fetch constant from class %s with a non-stringable type %s.', $className, $nameType->describe(VerbosityLevel::precise())))
8081
->identifier('classConstant.fetchInvalidExpression')
8182
->build();
8283
}

tests/PHPStan/Rules/Classes/ClassConstantRuleTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ public function testDynamicAccess(): void
449449
17,
450450
],
451451
[
452-
'Cannot fetch class constant with a non-stringable type object.',
452+
'Cannot fetch constant from class ClassConstantDynamicAccess\Foo with a non-stringable type object.',
453453
19,
454454
],
455455
[
@@ -494,31 +494,31 @@ public function testStringableDynamicAccess(): void
494494

495495
$this->analyse([__DIR__ . '/data/dynamic-constant-stringable-access.php'], [
496496
[
497-
'Cannot fetch class constant with a non-stringable type mixed.',
497+
'Cannot fetch constant from class ClassConstantDynamicStringableAccess\Foo with a non-stringable type mixed.',
498498
13,
499499
],
500500
[
501-
'Cannot fetch class constant with a non-stringable type string|null.',
501+
'Cannot fetch constant from class ClassConstantDynamicStringableAccess\Foo with a non-stringable type string|null.',
502502
14,
503503
],
504504
[
505-
'Cannot fetch class constant with a non-stringable type Stringable|null.',
505+
'Cannot fetch constant from class ClassConstantDynamicStringableAccess\Foo with a non-stringable type Stringable|null.',
506506
15,
507507
],
508508
[
509-
'Cannot fetch class constant with a non-stringable type int.',
509+
'Cannot fetch constant from class ClassConstantDynamicStringableAccess\Foo with a non-stringable type int.',
510510
16,
511511
],
512512
[
513-
'Cannot fetch class constant with a non-stringable type int|null.',
513+
'Cannot fetch constant from class ClassConstantDynamicStringableAccess\Foo with a non-stringable type int|null.',
514514
17,
515515
],
516516
[
517-
'Cannot fetch class constant with a non-stringable type DateTime|string.',
517+
'Cannot fetch constant from class ClassConstantDynamicStringableAccess\Foo with a non-stringable type DateTime|string.',
518518
18,
519519
],
520520
[
521-
'Cannot fetch class constant with a non-stringable type 1111.',
521+
'Cannot fetch constant from class ClassConstantDynamicStringableAccess\Foo with a non-stringable type 1111.',
522522
19,
523523
],
524524
]);

0 commit comments

Comments
 (0)