Skip to content

Commit 37c7d91

Browse files
authored
Merge pull request #35 from PHPCSStandards/feature/psr12-fileheader-more-modular-errorcode-spacing-after
4.0 | PSR12/FileHeader: make "SpacingAfter" and "SpacingInside" errorcodes modular
2 parents 73ca486 + c9c4d05 commit 37c7d91

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Standards/PSR12/Sniffs/Files/FileHeaderSniff.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,9 @@ public function processHeaderLines(File $phpcsFile, $headerLines)
301301
// this block.
302302
$next = $phpcsFile->findNext(T_WHITESPACE, ($line['end'] + 1), null, true);
303303
if ($next !== false && $tokens[$next]['line'] !== ($tokens[$line['end']]['line'] + 2)) {
304-
$error = 'Header blocks must be separated by a single blank line';
305-
$fix = $phpcsFile->addFixableError($error, $line['end'], 'SpacingAfterBlock');
304+
$error = 'Header blocks must be separated by a single blank line';
305+
$errorCode = 'SpacingAfter'.str_replace(' ', '', ucwords($line['type'])).'Block';
306+
$fix = $phpcsFile->addFixableError($error, $line['end'], $errorCode);
306307
if ($fix === true) {
307308
if ($tokens[$next]['line'] === $tokens[$line['end']]['line']) {
308309
$phpcsFile->fixer->addContentBefore($next, $phpcsFile->eolChar.$phpcsFile->eolChar);
@@ -340,8 +341,9 @@ public function processHeaderLines(File $phpcsFile, $headerLines)
340341
// blank line after this statement.
341342
$next = $phpcsFile->findNext(T_WHITESPACE, ($line['end'] + 1), null, true);
342343
if ($tokens[$next]['line'] > ($tokens[$line['end']]['line'] + 1)) {
343-
$error = 'Header blocks must not contain blank lines';
344-
$fix = $phpcsFile->addFixableError($error, $line['end'], 'SpacingInsideBlock');
344+
$error = 'Header blocks must not contain blank lines';
345+
$errorCode = 'SpacingInside'.str_replace(' ', '', ucwords($line['type'])).'Block';
346+
$fix = $phpcsFile->addFixableError($error, $line['end'], $errorCode);
345347
if ($fix === true) {
346348
$phpcsFile->fixer->beginChangeset();
347349
for ($i = ($line['end'] + 1); $i < $next; $i++) {
@@ -358,7 +360,7 @@ public function processHeaderLines(File $phpcsFile, $headerLines)
358360

359361
$phpcsFile->fixer->endChangeset();
360362
}
361-
}
363+
}//end if
362364
}//end if
363365

364366
if (isset($found[$line['type']]) === false) {

0 commit comments

Comments
 (0)