<commit_before><?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2012, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace li3_quality\test\rules;

class IncludeAndRequireWithoutBrackets extends \li3_quality\test\Rule {

	protected $_inspectableTokens = array(
		'T_INCLUDE'      => 'include statement should not use brackets',
		'T_INCLUDE_ONCE' => 'include_once statement should not use brackets',
		'T_REQUIRE'      => 'require statement should not use brackets',
		'T_REQUIRE_ONCE' => 'require_once statement should not use brackets'
	);

	public function apply($testable) {
		$tokens = $testable->tokens();

		foreach ($tokens as $key => $token) {
			if (in_array($token['name'], array_keys($this->_inspectableTokens))) {

				// Check next two tokens for brackets
				for ($i = 1; $i <= 2; $i++) {

					// Skip whitespace
					$hasWhitespace = $tokens[$key+$i]['name'] == 'T_WHITESPACE';
					if ($hasWhitespace) {
						continue;
					}

					// Check for brackets
					$usesBrackets = $tokens[$key+$i]['content'] == '(';
					if ($usesBrackets) {
						$this->addViolation(array(
							'message' => $this->_inspectableTokens[$token['name']],
							'line' => $token['line']
						));
					}
				}
			}
		}
	}
}

?><commit_msg>Refactoring rule to increase performance.<commit_after><?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2012, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace li3_quality\test\rules;

class IncludeAndRequireWithoutBrackets extends \li3_quality\test\Rule {

	protected $_inspectableTokens = array(
		'T_INCLUDE'      => 'include statement should not use brackets',
		'T_INCLUDE_ONCE' => 'include_once statement should not use brackets',
		'T_REQUIRE'      => 'require statement should not use brackets',
		'T_REQUIRE_ONCE' => 'require_once statement should not use brackets'
	);

	public function apply($testable) {
		$tokens = $testable->tokens();

		foreach ($tokens as $key => $token) {
			if(array_key_exists($token['name'], $this->_inspectableTokens)) {
				for ($i = 1; $i <= 2; $i++) {
					if ($tokens[$key+$i]['name'] == 'T_WHITESPACE') {
						continue;
					}

					if ($tokens[$key+$i]['content'] == '(') {
						$this->addViolation(array(
							'message' => $this->_inspectableTokens[$token['name']],
							'line' => $token['line']
						));
					}
				}
			}
		}
	}
}

?>
{'fraction_non_alphanumeric': 0.1610501567398119, 'fraction_numerical': 0.006269592476489028, 'mean_word_length': 3.4093264248704664, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, 'https://': 0, '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': '5004493', 'n_tokens_mistral': 1018, 'n_tokens_neox': 822, 'n_words': 190}