tab_width ) ) { $this->tab_width = PHPCSHelper::get_tab_width( $this->phpcsFile ); } $check_tokens = array( \T_WHITESPACE => true, \T_DOC_COMMENT_WHITESPACE => true, \T_DOC_COMMENT_STRING => true, ); for ( $i = ( $stackPtr + 1 ); $i < $this->phpcsFile->numTokens; $i++ ) { // Skip all non-whitespace tokens and skip whitespace at the start of a new line. if ( ! isset( $check_tokens[ $this->tokens[ $i ]['code'] ] ) || 1 === $this->tokens[ $i ]['column'] ) { continue; } // If tabs are being converted to spaces by the tokenizer, the // original content should be checked instead of the converted content. if ( isset( $this->tokens[ $i ]['orig_content'] ) ) { $content = $this->tokens[ $i ]['orig_content']; } else { $content = $this->tokens[ $i ]['content']; } if ( '' === $content || strpos( $content, "\t" ) === false ) { continue; } $fix = $this->phpcsFile->addFixableError( 'Spaces must be used for mid-line alignment; tabs are not allowed', $i, 'NonIndentTabsUsed' ); if ( true === $fix ) { if ( isset( $this->tokens[ $i ]['orig_content'] ) ) { // Use the replacement that PHPCS has already done. $this->phpcsFile->fixer->replaceToken( $i, $this->tokens[ $i ]['content'] ); } else { // Replace tabs with spaces, using an indent of $tab_width. // Other sniffs can then correct the indent if they need to. $spaces = str_repeat( ' ', $this->tab_width ); $newContent = str_replace( "\t", $spaces, $this->tokens[ $i ]['content'] ); $this->phpcsFile->fixer->replaceToken( $i, $newContent ); } } } // Ignore the rest of the file. return ( $this->phpcsFile->numTokens + 1 ); } }