<commit_before><?php
/**
 * PSR2_Sniffs_WhiteSpace_ControlStructureSpacingSniff.
 *
 * PHP version 5
 *
 * @category  PHP
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
 *
 * @link      http://pear.php.net/package/PHP_CodeSniffer
 */
namespace PSR2R\Sniffs\ControlStructures;

use PHP_CodeSniffer_File;
use PHP_CodeSniffer_Sniff;

/**
 * PSR2_Sniffs_WhiteSpace_ControlStructureSpacingSniff.
 *
 * Checks that control structures have the correct spacing around brackets.
 *
 * @category  PHP
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
 *
 * @version   Release: @package_version@
 *
 * @link      http://pear.php.net/package/PHP_CodeSniffer
 */
class ControlStructureSpacingSniff implements PHP_CodeSniffer_Sniff {

	/**
     * How many spaces should follow the opening bracket.
     *
     * @var int
     */
	public $requiredSpacesAfterOpen = 0;

	/**
     * How many spaces should precede the closing bracket.
     *
     * @var int
     */
	public $requiredSpacesBeforeClose = 0;

	/**
     * Returns an array of tokens this test wants to listen for.
     *
     * @return array
     */
	public function register() {
		return [
				T_IF,
				T_WHILE,
				T_FOREACH,
				T_FOR,
				T_SWITCH,
				T_DO,
				T_ELSE,
				T_ELSEIF,
				T_TRY,
				T_CATCH,
			   ];
	}//end register()


	/**
     * Processes this test, when one of its tokens is encountered.
     *
     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
     * @param int $stackPtr The position of the current token
     *   in the stack passed in $tokens.
     *
     * @return void
     */
	public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
		$this->requiredSpacesAfterOpen = (int) $this->requiredSpacesAfterOpen;
		$this->requiredSpacesBeforeClose = (int) $this->requiredSpacesBeforeClose;
		$tokens = $phpcsFile->getTokens();

		if (isset($tokens[$stackPtr]['parenthesis_opener']) === false
			|| isset($tokens[$stackPtr]['parenthesis_closer']) === false
		) {
			return;
		}

		$parenOpener = $tokens[$stackPtr]['parenthesis_opener'];
		$parenCloser = $tokens[$stackPtr]['parenthesis_closer'];
		$spaceAfterOpen = 0;
		if ($tokens[($parenOpener + 1)]['code'] === T_WHITESPACE) {
			if (strpos($tokens[($parenOpener + 1)]['content'], $phpcsFile->eolChar) !== false) {
				$spaceAfterOpen = 'newline';
			} else {
				$spaceAfterOpen = strlen($tokens[($parenOpener + 1)]['content']);
			}
		}

		$phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', $spaceAfterOpen);

		if ($spaceAfterOpen !== $this->requiredSpacesAfterOpen) {
			$error = 'Expected %s spaces after opening bracket; %s found';
			$data = [
					  $this->requiredSpacesAfterOpen,
					  $spaceAfterOpen,
					 ];
			$fix = $phpcsFile->addFixableError($error, ($parenOpener + 1), 'SpacingAfterOpenBrace', $data);
			if ($fix === true) {
				$padding = str_repeat(' ', $this->requiredSpacesAfterOpen);
				if ($spaceAfterOpen === 0) {
					$phpcsFile->fixer->addContent($parenOpener, $padding);
				} elseif ($spaceAfterOpen === 'newline') {
					$phpcsFile->fixer->replaceToken(($parenOpener + 1), '');
				} else {
					$phpcsFile->fixer->replaceToken(($parenOpener + 1), $padding);
				}
			}
		}

		if ($tokens[$parenOpener]['line'] === $tokens[$parenCloser]['line']) {
			$spaceBeforeClose = 0;
			if ($tokens[($parenCloser - 1)]['code'] === T_WHITESPACE) {
				$spaceBeforeClose = strlen(ltrim($tokens[($parenCloser - 1)]['content'], $phpcsFile->eolChar));
			}

			$phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', $spaceBeforeClose);

			if ($spaceBeforeClose !== $this->requiredSpacesBeforeClose) {
				$error = 'Expected %s spaces before closing bracket; %s found';
				$data = [
						  $this->requiredSpacesBeforeClose,
						  $spaceBeforeClose,
						 ];
				$fix = $phpcsFile->addFixableError($error, ($parenCloser - 1), 'SpaceBeforeCloseBrace', $data);
				if ($fix === true) {
					$padding = str_repeat(' ', $this->requiredSpacesBeforeClose);
					if ($spaceBeforeClose === 0) {
						$phpcsFile->fixer->addContentBefore($parenCloser, $padding);
					} else {
						$phpcsFile->fixer->replaceToken(($parenCloser - 1), $padding);
					}
				}
			}
		}//end if
	}//end process()
}//end class
<commit_msg>Soften sniffer.<commit_after><?php
/**
 * PSR2_Sniffs_WhiteSpace_ControlStructureSpacingSniff.
 *
 * PHP version 5
 *
 * @category  PHP
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
 *
 * @link      http://pear.php.net/package/PHP_CodeSniffer
 */
namespace PSR2R\Sniffs\ControlStructures;

use PHP_CodeSniffer_File;
use PHP_CodeSniffer_Sniff;

/**
 * PSR2_Sniffs_WhiteSpace_ControlStructureSpacingSniff.
 *
 * Checks that control structures have the correct spacing around brackets.
 *
 * @category  PHP
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
 *
 * @version   Release: @package_version@
 *
 * @link      http://pear.php.net/package/PHP_CodeSniffer
 */
class ControlStructureSpacingSniff implements PHP_CodeSniffer_Sniff {

	/**
     * How many spaces should follow the opening bracket.
     *
     * @var int
     */
	public $requiredSpacesAfterOpen = 0;

	/**
     * How many spaces should precede the closing bracket.
     *
     * @var int
     */
	public $requiredSpacesBeforeClose = 0;

	/**
     * Returns an array of tokens this test wants to listen for.
     *
     * @return array
     */
	public function register() {
		return [
				T_IF,
				T_WHILE,
				T_FOREACH,
				T_FOR,
				T_SWITCH,
				T_DO,
				T_ELSE,
				T_ELSEIF,
				T_TRY,
				T_CATCH,
			   ];
	}//end register()


	/**
     * Processes this test, when one of its tokens is encountered.
     *
     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
     * @param int $stackPtr The position of the current token
     *   in the stack passed in $tokens.
     *
     * @return void
     */
	public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
		$this->requiredSpacesAfterOpen = (int) $this->requiredSpacesAfterOpen;
		$this->requiredSpacesBeforeClose = (int) $this->requiredSpacesBeforeClose;
		$tokens = $phpcsFile->getTokens();

		if (isset($tokens[$stackPtr]['parenthesis_opener']) === false
			|| isset($tokens[$stackPtr]['parenthesis_closer']) === false
		) {
			return;
		}

		$parenOpener = $tokens[$stackPtr]['parenthesis_opener'];
		$parenCloser = $tokens[$stackPtr]['parenthesis_closer'];
		$spaceAfterOpen = 0;
		if ($tokens[($parenOpener + 1)]['code'] === T_WHITESPACE) {
			if (strpos($tokens[($parenOpener + 1)]['content'], $phpcsFile->eolChar) !== false) {
				$spaceAfterOpen = 'newline';
			} else {
				$spaceAfterOpen = strlen($tokens[($parenOpener + 1)]['content']);
			}
		}

		$phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', $spaceAfterOpen);

		if ($tokens[$parenOpener]['line'] === $tokens[$parenCloser]['line']) {
			if ($spaceAfterOpen !== $this->requiredSpacesAfterOpen) {
				$error = 'Expected %s spaces after opening bracket; %s found';
				$data = [
						  $this->requiredSpacesAfterOpen,
						  $spaceAfterOpen,
						 ];
				$fix = $phpcsFile->addFixableError($error, ($parenOpener + 1), 'SpacingAfterOpenBrace', $data);
				if ($fix === true) {
					$padding = str_repeat(' ', $this->requiredSpacesAfterOpen);
					if ($spaceAfterOpen === 0) {
						$phpcsFile->fixer->addContent($parenOpener, $padding);
					} elseif ($spaceAfterOpen === 'newline') {
						$phpcsFile->fixer->replaceToken(($parenOpener + 1), '');
					} else {
						$phpcsFile->fixer->replaceToken(($parenOpener + 1), $padding);
					}
				}
			}
		}

		if ($tokens[$parenOpener]['line'] === $tokens[$parenCloser]['line']) {
			$spaceBeforeClose = 0;
			if ($tokens[($parenCloser - 1)]['code'] === T_WHITESPACE) {
				$spaceBeforeClose = strlen(ltrim($tokens[($parenCloser - 1)]['content'], $phpcsFile->eolChar));
			}

			$phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', $spaceBeforeClose);

			if ($spaceBeforeClose !== $this->requiredSpacesBeforeClose) {
				$error = 'Expected %s spaces before closing bracket; %s found';
				$data = [
						  $this->requiredSpacesBeforeClose,
						  $spaceBeforeClose,
						 ];
				$fix = $phpcsFile->addFixableError($error, ($parenCloser - 1), 'SpaceBeforeCloseBrace', $data);
				if ($fix === true) {
					$padding = str_repeat(' ', $this->requiredSpacesBeforeClose);
					if ($spaceBeforeClose === 0) {
						$phpcsFile->fixer->addContentBefore($parenCloser, $padding);
					} else {
						$phpcsFile->fixer->replaceToken(($parenCloser - 1), $padding);
					}
				}
			}
		}//end if
	}//end process()
}//end class

{'fraction_non_alphanumeric': 0.15108305213889192, 'fraction_numerical': 0.012626537498639382, 'mean_word_length': 3.5643318430203674, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 69, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3521627', 'n_tokens_mistral': 3574, 'n_tokens_neox': 3059, 'n_words': 628}