Skip to content

Commit f9d4a82

Browse files
committed
fixup! Add class name to message
1 parent 4e59d4f commit f9d4a82

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/Rules/Classes/ClassConstantRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public function processNode(Node $node, Scope $scope): array
8181
? $scope->resolveName($node->class)
8282
: $scope->getType($node->class)->describe(VerbosityLevel::typeOnly());
8383

84-
$errors[] = RuleErrorBuilder::message(sprintf('Cannot fetch constant from %s with a non-stringable type %s.', $className, $nameType->describe(VerbosityLevel::precise())))
85-
->identifier('classConstant.fetchInvalidExpression')
84+
$errors[] = RuleErrorBuilder::message(sprintf('Class constant name for %s must be a string, but %s was given.', $className, $nameType->describe(VerbosityLevel::precise())))
85+
->identifier('classConstant.nameNotString')
8686
->build();
8787
}
8888
}

tests/PHPStan/Rules/Classes/ClassConstantRuleTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ public function testDynamicAccess(): void
449449
17,
450450
],
451451
[
452-
'Cannot fetch constant from ClassConstantDynamicAccess\Foo with a non-stringable type object.',
452+
'Class constant name for ClassConstantDynamicAccess\Foo must be a string, but object was given.',
453453
19,
454454
],
455455
[
@@ -494,51 +494,51 @@ public function testStringableDynamicAccess(): void
494494

495495
$this->analyse([__DIR__ . '/data/dynamic-constant-stringable-access.php'], [
496496
[
497-
'Cannot fetch constant from ClassConstantDynamicStringableAccess\Foo with a non-stringable type mixed.',
497+
'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but mixed was given.',
498498
14,
499499
],
500500
[
501-
'Cannot fetch constant from ClassConstantDynamicStringableAccess\Foo with a non-stringable type string|null.',
501+
'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but string|null was given.',
502502
15,
503503
],
504504
[
505-
'Cannot fetch constant from ClassConstantDynamicStringableAccess\Foo with a non-stringable type Stringable|null.',
505+
'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but Stringable|null was given.',
506506
16,
507507
],
508508
[
509-
'Cannot fetch constant from ClassConstantDynamicStringableAccess\Foo with a non-stringable type int.',
509+
'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but int was given.',
510510
17,
511511
],
512512
[
513-
'Cannot fetch constant from ClassConstantDynamicStringableAccess\Foo with a non-stringable type int|null.',
513+
'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but int|null was given.',
514514
18,
515515
],
516516
[
517-
'Cannot fetch constant from ClassConstantDynamicStringableAccess\Foo with a non-stringable type DateTime|string.',
517+
'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but DateTime|string was given.',
518518
19,
519519
],
520520
[
521-
'Cannot fetch constant from ClassConstantDynamicStringableAccess\Foo with a non-stringable type 1111.',
521+
'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but 1111 was given.',
522522
20,
523523
],
524524
[
525-
'Cannot fetch constant from ClassConstantDynamicStringableAccess\Foo with a non-stringable type Stringable.',
525+
'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but Stringable was given.',
526526
22,
527527
],
528528
[
529-
'Cannot fetch constant from ClassConstantDynamicStringableAccess\Foo with a non-stringable type mixed.',
529+
'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but mixed was given.',
530530
32,
531531
],
532532
[
533-
'Cannot fetch constant from ClassConstantDynamicStringableAccess\Bar with a non-stringable type mixed.',
533+
'Class constant name for ClassConstantDynamicStringableAccess\Bar must be a string, but mixed was given.',
534534
33,
535535
],
536536
[
537-
'Cannot fetch constant from DateTime|DateTimeImmutable with a non-stringable type mixed.',
537+
'Class constant name for DateTime|DateTimeImmutable must be a string, but mixed was given.',
538538
38,
539539
],
540540
[
541-
'Cannot fetch constant from object with a non-stringable type mixed.',
541+
'Class constant name for object must be a string, but mixed was given.',
542542
39,
543543
],
544544
]);

0 commit comments

Comments
 (0)