Skip to content

Commit 73ca486

Browse files
authored
Merge pull request #1009 from PHPCSStandards/phpcs-4.0/feature/sq-2318-squiz-heredoc-split-errorcode
Squiz/Heredoc: make sniff more modular
2 parents 2a112a1 + 89ee097 commit 73ca486

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Standards/Squiz/Sniffs/PHP/HeredocSniff.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,19 @@ public function register()
4242
*/
4343
public function process(File $phpcsFile, $stackPtr)
4444
{
45-
$error = 'Use of heredoc and nowdoc syntax ("<<<") is not allowed; use standard strings or inline HTML instead';
46-
$phpcsFile->addError($error, $stackPtr, 'NotAllowed');
45+
$tokens = $phpcsFile->getTokens();
46+
47+
$codePrefix = 'Heredoc';
48+
$data = ['heredoc'];
49+
if ($tokens[$stackPtr]['code'] === T_START_NOWDOC) {
50+
$codePrefix = 'Nowdoc';
51+
$data = ['nowdoc'];
52+
}
53+
54+
$data[] = trim($tokens[$stackPtr]['content']);
55+
56+
$error = 'Use of %s syntax (%s) is not allowed; use standard strings or inline HTML instead';
57+
$phpcsFile->addError($error, $stackPtr, $codePrefix.'NotAllowed', $data);
4758

4859
}//end process()
4960

0 commit comments

Comments
 (0)