WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php
public function process_token( $stackPtr ) {

		switch ( $this->tokens[ $stackPtr ]['type'] ) {
			/*
			 * Detect `something();;`.
			 */
			case 'T_SEMICOLON':
				$prevNonEmpty = $this->phpcsFile->findPrevious(
					Tokens::$emptyTokens,
					( $stackPtr - 1 ),
					null,
					true
				);

				if ( false === $prevNonEmpty
					|| ( \T_SEMICOLON !== $this->tokens[ $prevNonEmpty ]['code']
						&& \T_OPEN_TAG !== $this->tokens[ $prevNonEmpty ]['code']
						&& \T_OPEN_TAG_WITH_ECHO !== $this->tokens[ $prevNonEmpty ]['code'] )
				) {
					return;
				}

				if ( isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) {
					$nested      = $this->tokens[ $stackPtr ]['nested_parenthesis'];
					$last_closer = array_pop( $nested );
					if ( isset( $this->tokens[ $last_closer ]['parenthesis_owner'] )
						&& \T_FOR === $this->tokens[ $this->tokens[ $last_closer ]['parenthesis_owner'] ]['code']
					) {
						// Empty for() condition.
						return;
					}
				}

				$fix = $this->phpcsFile->addFixableWarning(
					'Empty PHP statement detected: superfluous semi-colon.',
					$stackPtr,
					'SemicolonWithoutCodeDetected'
				);
				if ( true === $fix ) {
					$this->phpcsFile->fixer->beginChangeset();

					if ( \T_OPEN_TAG === $this->tokens[ $prevNonEmpty ]['code']
						|| \T_OPEN_TAG_WITH_ECHO === $this->tokens[ $prevNonEmpty ]['code']
					) {
						/*
						 * Check for superfluous whitespace after the semi-colon which will be
						 * removed as the `<?php ` open tag token already contains whitespace,
						 * either a space or a new line and in case of a new line, the indentation
						 * should be done via tabs, so spaces can be safely removed.
						 */
						if ( \T_WHITESPACE === $this->tokens[ ( $stackPtr + 1 ) ]['code'] ) {
							$replacement = str_replace( ' ', '', $this->tokens[ ( $stackPtr + 1 ) ]['content'] );
							$this->phpcsFile->fixer->replaceToken( ( $stackPtr + 1 ), $replacement );
						}
					}

					for ( $i = $stackPtr; $i > $prevNonEmpty; $i-- ) {
						if ( \T_SEMICOLON !== $this->tokens[ $i ]['code']
							&& \T_WHITESPACE !== $this->tokens[ $i ]['code']
						) {
							break;
						}
						$this->phpcsFile->fixer->replaceToken( $i, '' );
					}

					$this->phpcsFile->fixer->endChangeset();
				}
				break;

			/*
			 * Detect `<?php ?>`.
			 */
			case 'T_CLOSE_TAG':
				$prevNonEmpty = $this->phpcsFile->findPrevious(
					\T_WHITESPACE,
					( $stackPtr - 1 ),
					null,
					true
				);

				if ( false === $prevNonEmpty
					|| ( \T_OPEN_TAG !== $this->tokens[ $prevNonEmpty ]['code']
						&& \T_OPEN_TAG_WITH_ECHO !== $this->tokens[ $prevNonEmpty ]['code'] )
				) {
					return;
				}

				$fix = $this->phpcsFile->addFixableWarning(
					'Empty PHP open/close tag combination detected.',
					$prevNonEmpty,
					'EmptyPHPOpenCloseTagsDetected'
				);
				if ( true === $fix ) {
					$this->phpcsFile->fixer->beginChangeset();
					for ( $i = $prevNonEmpty; $i <= $stackPtr; $i++ ) {
						$this->phpcsFile->fixer->replaceToken( $i, '' );
					}
					$this->phpcsFile->fixer->endChangeset();
				}
				break;

			default:
				/* Deliberately left empty. */
				break;
		}
	}
public function process_token( $stackPtr ) {

		switch ( $this->tokens[ $stackPtr ]['type'] ) {
			/*
			 * Detect `something();;`.
			 */
			case 'T_SEMICOLON':
				$prevNonEmpty = $this->phpcsFile->findPrevious(
					Tokens::$emptyTokens,
					( $stackPtr - 1 ),
					null,
					true
				);

				if ( false === $prevNonEmpty
					|| ( \T_SEMICOLON !== $this->tokens[ $prevNonEmpty ]['code']
						&& \T_OPEN_TAG !== $this->tokens[ $prevNonEmpty ]['code']
						&& \T_OPEN_TAG_WITH_ECHO !== $this->tokens[ $prevNonEmpty ]['code'] )
				) {
					return;
				}

				if ( isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) {
					$nested      = $this->tokens[ $stackPtr ]['nested_parenthesis'];
					$last_closer = array_pop( $nested );
					if ( isset( $this->tokens[ $last_closer ]['parenthesis_owner'] )
						&& \T_FOR === $this->tokens[ $this->tokens[ $last_closer ]['parenthesis_owner'] ]['code']
					) {
						// Empty for() condition.
						return;
					}
				}

				$fix = $this->phpcsFile->addFixableWarning(
					'Empty PHP statement detected: superfluous semi-colon.',
					$stackPtr,
					'SemicolonWithoutCodeDetected'
				);
				if ( true === $fix ) {
					$this->phpcsFile->fixer->beginChangeset();

					if ( \T_OPEN_TAG === $this->tokens[ $prevNonEmpty ]['code']
						|| \T_OPEN_TAG_WITH_ECHO === $this->tokens[ $prevNonEmpty ]['code']
					) {
						/*
						 * Check for superfluous whitespace after the semi-colon which will be
						 * removed as the `<?php ` open tag token already contains whitespace,
						 * either a space or a new line and in case of a new line, the indentation
						 * should be done via tabs, so spaces can be safely removed.
						 */
						if ( \T_WHITESPACE === $this->tokens[ ( $stackPtr + 1 ) ]['code'] ) {
							$replacement = str_replace( ' ', '', $this->tokens[ ( $stackPtr + 1 ) ]['content'] );
							$this->phpcsFile->fixer->replaceToken( ( $stackPtr + 1 ), $replacement );
						}
					}

					for ( $i = $stackPtr; $i > $prevNonEmpty; $i-- ) {
						if ( \T_SEMICOLON !== $this->tokens[ $i ]['code']
							&& \T_WHITESPACE !== $this->tokens[ $i ]['code']
						) {
							break;
						}
						$this->phpcsFile->fixer->replaceToken( $i, '' );
					}

					$this->phpcsFile->fixer->endChangeset();
				}
				break;

			/*
			 * Detect `<?php ?>`.
			 */
			case 'T_CLOSE_TAG':
				$prevNonEmpty = $this->phpcsFile->findPrevious(
					\T_WHITESPACE,
					( $stackPtr - 1 ),
					null,
					true
				);

				if ( false === $prevNonEmpty
					|| ( \T_OPEN_TAG !== $this->tokens[ $prevNonEmpty ]['code']
						&& \T_OPEN_TAG_WITH_ECHO !== $this->tokens[ $prevNonEmpty ]['code'] )
				) {
					return;
				}

				$fix = $this->phpcsFile->addFixableWarning(
					'Empty PHP open/close tag combination detected.',
					$prevNonEmpty,
					'EmptyPHPOpenCloseTagsDetected'
				);
				if ( true === $fix ) {
					$this->phpcsFile->fixer->beginChangeset();
					for ( $i = $prevNonEmpty; $i <= $stackPtr; $i++ ) {
						$this->phpcsFile->fixer->replaceToken( $i, '' );
					}
					$this->phpcsFile->fixer->endChangeset();
				}
				break;

			default:
				/* Deliberately left empty. */
				break;
		}
	}
Processes this test, when one of its tokens is encountered.

@param int $stackPtr The position of the current token in the stack.

@return int Integer stack pointer to skip the rest of the file.