<commit_before><?php namespace System\DB\Query;

use System\Str;

class Dynamic {

	/**
	 * Add conditions to a query from a dynamic method call.
	 *
	 * @param  string  $method
	 * @param  array   $parameters
	 * @param  Query   $query
	 * @return Query
	 */
	public static function build($method, $parameters, $query)
	{
		// ---------------------------------------------------------
		// Strip the "where_" off of the method.
		// ---------------------------------------------------------
		$method = substr($method, 6);

		// ---------------------------------------------------------
		// Split the column names from the connectors.
		// ---------------------------------------------------------
		$segments = preg_split('/(_and_|_or_)/i', $method, -1, PREG_SPLIT_DELIM_CAPTURE);

		// ---------------------------------------------------------
		// The connector variable will determine which connector
		// will be used for the condition. We'll change it as we
		// come across new connectors in the dynamic method string.
		//
		// The index variable helps us get the correct parameter
		// value for the where condition. We increment it each time
		// we add a condition.
		// ---------------------------------------------------------
		$connector = 'AND';

		$index = 0;

		// ---------------------------------------------------------
		// Iterate through each segment and add the conditions.
		// ---------------------------------------------------------
		foreach ($segments as $segment)
		{
			if ($segment != '_and_' and $segment != '_or_')
			{
				$query->where($segment, '=', $parameters[$index], $connector);

				$index++;
			}
			else
			{
				$connector = trim(Str::upper($segment), '_');
			}
		}

		return $query;
	}

}<commit_msg>added exception for wrong number of parameters to dynamic finders.<commit_after><?php namespace System\DB\Query;

use System\Str;

class Dynamic {

	/**
	 * Add conditions to a query from a dynamic method call.
	 *
	 * @param  string  $method
	 * @param  array   $parameters
	 * @param  Query   $query
	 * @return Query
	 */
	public static function build($method, $parameters, $query)
	{
		// ---------------------------------------------------------
		// Strip the "where_" off of the method.
		// ---------------------------------------------------------
		$finder = substr($method, 6);

		// ---------------------------------------------------------
		// Split the column names from the connectors.
		// ---------------------------------------------------------
		$segments = preg_split('/(_and_|_or_)/i', $finder, -1, PREG_SPLIT_DELIM_CAPTURE);

		// ---------------------------------------------------------
		// The connector variable will determine which connector
		// will be used for the condition. We'll change it as we
		// come across new connectors in the dynamic method string.
		//
		// The index variable helps us get the correct parameter
		// value for the where condition. We increment it each time
		// we add a condition.
		// ---------------------------------------------------------
		$connector = 'AND';

		$index = 0;

		// ---------------------------------------------------------
		// Iterate through each segment and add the conditions.
		// ---------------------------------------------------------
		foreach ($segments as $segment)
		{
			if ($segment != '_and_' and $segment != '_or_')
			{
				if ( ! array_key_exists($index, $parameters))
				{
					throw new \Exception("Wrong number of parameters for dynamic finder [$method].");					
				}

				$query->where($segment, '=', $parameters[$index], $connector);

				$index++;
			}
			else
			{
				$connector = trim(Str::upper($segment), '_');
			}
		}

		return $query;
	}

}
{'fraction_non_alphanumeric': 0.3467133620689655, 'fraction_numerical': 0.0016163793103448276, 'mean_word_length': 1.2035608308605341, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6931312', 'n_tokens_mistral': 1039, 'n_tokens_neox': 873, 'n_words': 296}