Skip to content

Commit 8765b74

Browse files
committed
Arrays/ArrayDeclarationSpacing: implement PHPCSUtils [4]
1 parent a0b40fd commit 8765b74

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -382,28 +382,15 @@ protected function process_multi_line_array( $stackPtr, $opener, $closer ) {
382382
}
383383

384384
if ( $this->tokens[ $end_of_last_item ]['line'] === $this->tokens[ $first_content ]['line'] ) {
385-
386-
$fix = $this->phpcsFile->addFixableError(
387-
'Each item in a multi-line array must be on a new line',
385+
SpacesFixer::checkAndFix(
386+
$this->phpcsFile,
388387
$first_content,
389-
'ArrayItemNoNewLine'
388+
$end_of_last_item,
389+
'newline',
390+
'Each item in a multi-line array must be on %s. Found: %s',
391+
'ArrayItemNoNewLine',
392+
'error'
390393
);
391-
392-
if ( true === $fix ) {
393-
394-
$this->phpcsFile->fixer->beginChangeset();
395-
396-
if ( ( $end_of_last_item + 1 ) <= ( $first_content - 1 )
397-
&& \T_WHITESPACE === $this->tokens[ ( $first_content - 1 ) ]['code']
398-
) {
399-
// Remove whitespace which would otherwise becoming trailing
400-
// (as it gives problems with the fixed file).
401-
$this->phpcsFile->fixer->replaceToken( ( $first_content - 1 ), '' );
402-
}
403-
404-
$this->phpcsFile->fixer->addNewlineBefore( $first_content );
405-
$this->phpcsFile->fixer->endChangeset();
406-
}
407394
}
408395

409396
$end_of_last_item = $end_of_this_item;

0 commit comments

Comments
 (0)