Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ The file documents changes to the PHP_CodeSniffer project.
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3854 : Fatal error when using Gitblame report in combination with `--basepath` and running from project subdirectory
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3856 : PSR12.Traits.UseDeclaration was using the wrong error code - SpacingAfterAs - for spacing issues after the use keyword
- These will now be reported using the SpacingAfterUse error code.
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3856 : PSR12.Traits.UseDeclaration did not check spacing after use keyword for multi-line trait use statements
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3867 : Tokenizer/PHP: union type and intersection type operators were not correctly tokenized for static properties without explicit visibility
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3877 : Filter names can be case-sensitive. The -h help text will now display the correct case for the available filters
Expand Down
64 changes: 32 additions & 32 deletions src/Standards/PSR12/Sniffs/Traits/UseDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,38 @@ public function process(File $phpcsFile, $stackPtr)
}//end if
}//end if

$error = 'Expected 1 space after USE in trait import statement; %s found';
if ($tokens[($useToken + 1)]['code'] !== T_WHITESPACE) {
$data = ['0'];
$fix = $phpcsFile->addFixableError($error, $useToken, 'SpaceAfterUse', $data);
if ($fix === true) {
$phpcsFile->fixer->addContent($useToken, ' ');
}
} else if ($tokens[($useToken + 1)]['content'] !== ' ') {
$next = $phpcsFile->findNext(T_WHITESPACE, ($useToken + 1), null, true);
if ($tokens[$next]['line'] !== $tokens[$useToken]['line']) {
$found = 'newline';
} else {
$found = $tokens[($useToken + 1)]['length'];
}

$data = [$found];
$fix = $phpcsFile->addFixableError($error, $useToken, 'SpaceAfterUse', $data);
if ($fix === true) {
if ($found === 'newline') {
$phpcsFile->fixer->beginChangeset();
for ($x = ($useToken + 1); $x < $next; $x++) {
$phpcsFile->fixer->replaceToken($x, '');
}

$phpcsFile->fixer->addContent($useToken, ' ');
$phpcsFile->fixer->endChangeset();
} else {
$phpcsFile->fixer->replaceToken(($useToken + 1), ' ');
}
}
}//end if

// Check the formatting of the statement.
if (isset($tokens[$useToken]['scope_opener']) === true) {
$this->processUseGroup($phpcsFile, $useToken);
Expand Down Expand Up @@ -652,38 +684,6 @@ protected function processUseStatement(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

$error = 'Expected 1 space after USE in trait import statement; %s found';
if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
$data = ['0'];
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterAs', $data);
if ($fix === true) {
$phpcsFile->fixer->addContent($stackPtr, ' ');
}
} else if ($tokens[($stackPtr + 1)]['content'] !== ' ') {
$next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
$found = 'newline';
} else {
$found = $tokens[($stackPtr + 1)]['length'];
}

$data = [$found];
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterAs', $data);
if ($fix === true) {
if ($found === 'newline') {
$phpcsFile->fixer->beginChangeset();
for ($x = ($stackPtr + 1); $x < $next; $x++) {
$phpcsFile->fixer->replaceToken($x, '');
}

$phpcsFile->fixer->addContent($stackPtr, ' ');
$phpcsFile->fixer->endChangeset();
} else {
$phpcsFile->fixer->replaceToken(($stackPtr + 1), ' ');
}
}
}//end if

$next = $phpcsFile->findNext([T_COMMA, T_SEMICOLON], ($stackPtr + 1));
if ($next !== false && $tokens[$next]['code'] === T_COMMA) {
$error = 'Each imported trait must have its own "use" import statement';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ClassName7

class ClassName8
{
use A , B,
use A , B,
C
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getErrorList()
29 => 2,
30 => 1,
42 => 1,
57 => 3,
57 => 4,
59 => 3,
61 => 1,
63 => 5,
Expand Down