<commit_before><?php
class Rules
{
	/* Connection to MySQL database */
	private $connection;

	/* Private properties (exposed via Getter) */
	private $_description;
	private $_preprocess;
	private $_postprocess;
	private $_query;
	private $_message;
	private $_output;


	private function connect( $host, $username, $password, $database )
	{
		$this->connection = new mysqli( $host, $username, $password, $database );
	}


	private function disconnect()
	{
		$this->connection->close();
	}


	/* Get rule data */
	private function get_rule_data( $ruleid )
	{
		if ( $results = $this->connection->query( "select rule_desc
			                                       ,      rule_query
			                                       ,      rule_message
			                                       ,      rule_active
			                                       ,      rule_preproc
			                                       ,      rule_postproc
			                                       from   rules
			                                       where  rule_id = ${ruleid}" ) ) {
			$row = mysqli_fetch_array( $results );
			$this->_description = $row[0];
			$this->_query = $row[1];
			$this->_message = $row[2];
			$this->_active = $row[3];
			$this->_preprocess = $row[4];
			$this->_postprocess = $row[5];
		}
	}


	public function run_rule( $ruleid )
	{
		/* Get rule data */
		$this->get_rule_data( $ruleid );

		if ( $this->active == 'Y' ) {
			/* Clear any previous output */
			$this->_output = null;

			/* Execute pre process */
			if ( strlen( $this->_preprocess ) > 0 ) {
				$this->connection->query( $this->_preprocess );
			}

			/* Execute the actual rule */
			$rule_result = $this->connection->query( $this->_query );

			/* Format the message */
			if ( mysqli_num_rows( $rule_result ) > 0 ) {
				$this->_output = sprintf( $this->_message, mysqli_fetch_array( $rule_result, MYSQLI_NUM ) );
			}

			/* Execute post process */
			if ( strlen( $this->_postprocess ) > 0 ) {
				$this->connection->query( $this->_postprocess );
			}

			/* Update last usage timestamp for rule */
			$this->connection->query( "update rules set rule_last_used=now() where rule_id = ${rule_id}" );

			/* Result result message */
			return ( strlen( $this->_output ) > 0 );
		} 

		/* Return failed indicator */
		return false;
	}


	/* Default Getter */
	public function __get( $property ) {<commit_msg>Added private for active field<commit_after><?php
class Rules
{
	/* Connection to MySQL database */
	private $connection;

	/* Private properties (exposed via Getter) */
	private $_description;
	private $_preprocess;
	private $_postprocess;
	private $_query;
	private $_message;
	private $_output;
	private $_active;


	private function connect( $host, $username, $password, $database )
	{
		$this->connection = new mysqli( $host, $username, $password, $database );
	}


	private function disconnect()
	{
		$this->connection->close();
	}


	/* Get rule data */
	private function get_rule_data( $ruleid )
	{
		if ( $results = $this->connection->query( "select rule_desc
			                                       ,      rule_query
			                                       ,      rule_message
			                                       ,      rule_active
			                                       ,      rule_preproc
			                                       ,      rule_postproc
			                                       from   rules
			                                       where  rule_id = ${ruleid}" ) ) {
			$row = mysqli_fetch_array( $results );
			$this->_description = $row[0];
			$this->_query = $row[1];
			$this->_message = $row[2];
			$this->_active = $row[3];
			$this->_preprocess = $row[4];
			$this->_postprocess = $row[5];
		}
	}


	public function run_rule( $ruleid )
	{
		/* Get rule data */
		$this->get_rule_data( $ruleid );

		if ( $this->_active == 'Y' ) {
			/* Clear any previous output */
			$this->_output = null;

			/* Execute pre process */
			if ( strlen( $this->_preprocess ) > 0 ) {
				$this->connection->query( $this->_preprocess );
			}

			/* Execute the actual rule */
			$rule_result = $this->connection->query( $this->_query );

			/* Format the message */
			if ( mysqli_num_rows( $rule_result ) > 0 ) {
				$this->_output = sprintf( $this->_message, mysqli_fetch_array( $rule_result, MYSQLI_NUM ) );
			}

			/* Execute post process */
			if ( strlen( $this->_postprocess ) > 0 ) {
				$this->connection->query( $this->_postprocess );
			}

			/* Update last usage timestamp for rule */
			$this->connection->query( "update rules set rule_last_used=now() where rule_id = ${ruleid}" );

			/* Result result message */
			return ( strlen( $this->_output ) > 0 );
		} 

		/* Return failed indicator */
		return false;
	}


	/* Default Getter */
	public function __get( $property ) {
{'fraction_non_alphanumeric': 0.13827571845064557, 'fraction_numerical': 0.004164931278633903, 'mean_word_length': 2.0093984962406015, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '848220', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1397, 'n_words': 344}