Skip to content

Commit b3132a4

Browse files
committed
ModernClassNameReferenceSniff: Fixed error messages
1 parent c20d323 commit b3132a4

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

SlevomatCodingStandard/Sniffs/Classes/ModernClassNameReferenceSniff.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use const T_STRING;
1313
use const T_VARIABLE;
1414
use function in_array;
15+
use function sprintf;
1516
use function strtolower;
1617

1718
class ModernClassNameReferenceSniff implements Sniff
@@ -50,7 +51,7 @@ public function process(File $phpcsFile, $pointer): void
5051

5152
private function checkMagicConstant(File $phpcsFile, int $pointer): void
5253
{
53-
$fix = $phpcsFile->addFixableError('Class name referenced via magic constant', $pointer, self::CODE_CLASS_NAME_REFERENCED_VIA_MAGIC_CONSTANT);
54+
$fix = $phpcsFile->addFixableError('Class name referenced via magic constant.', $pointer, self::CODE_CLASS_NAME_REFERENCED_VIA_MAGIC_CONSTANT);
5455

5556
if (!$fix) {
5657
return;
@@ -111,7 +112,7 @@ private function checkFunctionCall(File $phpcsFile, int $pointer): void
111112
$fixedContent = 'static::class';
112113
}
113114

114-
$fix = $phpcsFile->addFixableError('Class name referenced via call of function %s', $pointer, self::CODE_CLASS_NAME_REFERENCED_VIA_FUNCTION_CALL);
115+
$fix = $phpcsFile->addFixableError(sprintf('Class name referenced via call of function %s().', $functionName), $pointer, self::CODE_CLASS_NAME_REFERENCED_VIA_FUNCTION_CALL);
115116

116117
if (!$fix) {
117118
return;

tests/Sniffs/Classes/ModernClassNameReferenceSniffTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ public function testErrors(): void
2020
self::assertSame(5, $report->getErrorCount());
2121

2222
self::assertSniffError($report, 12, ModernClassNameReferenceSniff::CODE_CLASS_NAME_REFERENCED_VIA_MAGIC_CONSTANT);
23-
self::assertSniffError($report, 17, ModernClassNameReferenceSniff::CODE_CLASS_NAME_REFERENCED_VIA_FUNCTION_CALL);
24-
self::assertSniffError($report, 22, ModernClassNameReferenceSniff::CODE_CLASS_NAME_REFERENCED_VIA_FUNCTION_CALL);
25-
self::assertSniffError($report, 27, ModernClassNameReferenceSniff::CODE_CLASS_NAME_REFERENCED_VIA_FUNCTION_CALL);
26-
self::assertSniffError($report, 32, ModernClassNameReferenceSniff::CODE_CLASS_NAME_REFERENCED_VIA_FUNCTION_CALL);
23+
self::assertSniffError($report, 17, ModernClassNameReferenceSniff::CODE_CLASS_NAME_REFERENCED_VIA_FUNCTION_CALL, 'Class name referenced via call of function get_class().');
24+
self::assertSniffError($report, 22, ModernClassNameReferenceSniff::CODE_CLASS_NAME_REFERENCED_VIA_FUNCTION_CALL, 'Class name referenced via call of function get_class().');
25+
self::assertSniffError($report, 27, ModernClassNameReferenceSniff::CODE_CLASS_NAME_REFERENCED_VIA_FUNCTION_CALL, 'Class name referenced via call of function get_parent_class().');
26+
self::assertSniffError($report, 32, ModernClassNameReferenceSniff::CODE_CLASS_NAME_REFERENCED_VIA_FUNCTION_CALL, 'Class name referenced via call of function get_called_class().');
2727

2828
self::assertAllFixedInFile($report);
2929
}

0 commit comments

Comments
 (0)