Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
11 / 11
AlternativeSyntaxSniff
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
11 / 11
 register
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
6 / 6
 process
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
5 / 5
<?php
/**
 * Verify alternative syntax is not being used
 */
namespace MediaWiki\Sniffs\AlternativeSyntax;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
class AlternativeSyntaxSniff implements Sniff {
    /**
     * @inheritDoc
     */
    public function register() : array {
        // Per https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP
        // section on alternative syntax.
        return [
            T_ENDDECLARE,
            T_ENDFOR,
            T_ENDFOREACH,
            T_ENDIF,
            T_ENDSWITCH,
            T_ENDWHILE,
        ];
    }
    /**
     * @param File $phpcsFile
     * @param int $stackPtr The current token index.
     * @return void
     */
    public function process( File $phpcsFile, $stackPtr ) {
        $tokens = $phpcsFile->getTokens();
        $error = 'Alternative syntax such as "%s" should not be used';
        $data = [ $tokens[$stackPtr]['content'] ];
        $phpcsFile->addWarning( $error, $stackPtr, 'AlternativeSyntax', $data );
    }
}