<commit_before><?php
namespace PHP_CodeSniffer\Standards\TribalScents\Sniffs\CodeAnalysis;

use PHP_CodeSniffer\Sniffs;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;

/**
 * TribalScents_Sniffs_CodeAnalysis_RedirectAndDieSniff
 *
 * Throw an error if error loggins functions are in use
 *
 * @category  PHP
 * @package   PHP_CodeSniffer
 * @author    <NAME> <<EMAIL>>
 * @copyright 2014 ModernTribe
 * @license   https://github.com/moderntribe/TribalScents/blob/master/licence.txt BSD Licence
 * @version   Release: 1.4.0
 * @link      http://pear.php.net/package/PHP_CodeSniffer
 */
class RedirectAndDieSniff implements Sniff
{
	/**
	 * A list of tokenizers this sniff supports.
	 *
	 * @var array
	 */
	public $supportedTokenizers = array(
		'PHP',
	);

	/**
	 * Returns an array of tokens this test wants to listen for.
	 *
	 * @return array
	 */
	public function register()
	{
		return array(
			T_STRING,
		);
	}//end register

	/**
	 * Processes this test, when one of its tokens is encountered.
	 *
	 * @param 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( File $phpcsFile, $stackPtr )
	{
		$tokens = $phpcsFile->getTokens();
		$token = $tokens[ $stackPtr ];
		$function = strtolower( $token['content'] );

		$ignore = array(
			T_DOUBLE_COLON,
			T_OBJECT_OPERATOR,
			T_FUNCTION,
			T_CONST,
		);

		$prevToken = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true );

		if ( in_array( $tokens[ $prevToken ]['code'], $ignore ) === true )
		{
			// Not a call to a PHP function.
			return;
		}//end if

		if ( ! in_array( $function, array( 'wp_redirect', 'wp_safe_redirect' ) ) )
		{
			return;
		}//end if

		$semicolon = $phpcsFile->findNext( T_SEMICOLON, $stackPtr );
		$next = $tokens[ $phpcsFile->findNext( T_WHITESPACE, $semicolon + 1, NULL, TRUE ) ];

		if ( T_EXIT == $next['code'] || 'tribe_exit' == $next['code'] )
		{
			return;
		}//end if

		$data = array( $function );
		$type  = 'Error';
		$error = "die must follow {$function}";
		$phpcsFile->addError( $error, $stackPtr, $type, $data );
	}//end process
}//end class
<commit_msg>Properly identify tribe_exit() so we bail if we are using it correctly<commit_after><?php
namespace PHP_CodeSniffer\Standards\TribalScents\Sniffs\CodeAnalysis;

use PHP_CodeSniffer\Sniffs;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;

/**
 * TribalScents_Sniffs_CodeAnalysis_RedirectAndDieSniff
 *
 * Throw an error if error loggins functions are in use
 *
 * @category  PHP
 * @package   PHP_CodeSniffer
 * @author    <NAME> <<EMAIL>>
 * @copyright 2014 ModernTribe
 * @license   https://github.com/moderntribe/TribalScents/blob/master/licence.txt BSD Licence
 * @version   Release: 1.4.0
 * @link      http://pear.php.net/package/PHP_CodeSniffer
 */
class RedirectAndDieSniff implements Sniff
{
	/**
	 * A list of tokenizers this sniff supports.
	 *
	 * @var array
	 */
	public $supportedTokenizers = array(
		'PHP',
	);

	/**
	 * Returns an array of tokens this test wants to listen for.
	 *
	 * @return array
	 */
	public function register()
	{
		return array(
			T_STRING,
		);
	}//end register

	/**
	 * Processes this test, when one of its tokens is encountered.
	 *
	 * @param 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( File $phpcsFile, $stackPtr )
	{
		$tokens = $phpcsFile->getTokens();
		$token = $tokens[ $stackPtr ];
		$function = strtolower( $token['content'] );

		$ignore = array(
			T_DOUBLE_COLON,
			T_OBJECT_OPERATOR,
			T_FUNCTION,
			T_CONST,
		);

		$prevToken = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true );

		if ( in_array( $tokens[ $prevToken ]['code'], $ignore ) === true )
		{
			// Not a call to a PHP function.
			return;
		}//end if

		if ( ! in_array( $function, array( 'wp_redirect', 'wp_safe_redirect' ) ) )
		{
			return;
		}//end if

		$semicolon = $phpcsFile->findNext( T_SEMICOLON, $stackPtr );
		$next = $tokens[ $phpcsFile->findNext( T_WHITESPACE, $semicolon + 1, NULL, TRUE ) ];

		if ( T_EXIT == $next['code'] || 'tribe_exit' == $next['content'] )
		{
			return;
		}//end if

		$data = array( $function );
		$type  = 'Error';
		$error = "die must follow {$function}";
		$phpcsFile->addError( $error, $stackPtr, $type, $data );
	}//end process
}//end class

{'fraction_non_alphanumeric': 0.13799051315222077, 'fraction_numerical': 0.0038809831824062097, 'mean_word_length': 3.3355140186915886, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '402176', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1608, 'n_words': 421}