<commit_before><?php

/**
 * This file is part of the Nextras\Dbal library.
 * @license    MIT
 * @link       https://github.com/nextras/dbal
 */

namespace  Nextras\Dbal;

use Nextras\Dbal\Drivers\IDriverProvider;
use Nextras\Dbal\Drivers\IDriver;
use Nextras\Dbal\Exceptions\InvalidArgumentException;


class SqlProcessor
{
	/** @var IDriverProvider */
	private $driver;


	public function __construct(IDriver $driver)
	{
		$this->driver = $driver;
	}


	public function process(array $args)
	{
		$last = count($args) - 1;
		$query = '';

		for ($i = 0, $j = 0; $j <= $last; $j++) {
			if (!is_string($args[$j])) {
				if ($j === 0) {
					throw new InvalidArgumentException('Query fragment must be string.');
				} else {
					throw new InvalidArgumentException("Redundant query parameter or missing modifier in query fragment '$args[$i]'.");
				}
			}

			$i = $j;
			if ($i > 0) {
				$query .= ' ';
			}

			$query .= preg_replace_callback(
				'#%(\w++\??+(?:\[\])?+)|(\[.+?\])#',
				function ($matches) use ($args, &$j, $last) {
					if ($matches[1] !== '') {
						if ($j === $last) {
							throw new InvalidArgumentException("Missing query parameter for modifier $matches[0].");
						}
						return $this->processValue($args[++$j], $matches[1]);

					} else {
						return $this->driver->convertToSql(substr($matches[2], 1, -1), IDriver::TYPE_IDENTIFIER);
					}
				},
				$args[$i]
			);

			if ($i === $j && $j !== $last) {<commit_msg>SqlProcessor: minor refactoring<commit_after><?php

/**
 * This file is part of the Nextras\Dbal library.
 * @license    MIT
 * @link       https://github.com/nextras/dbal
 */

namespace  Nextras\Dbal;

use Nextras\Dbal\Drivers\IDriverProvider;
use Nextras\Dbal\Drivers\IDriver;
use Nextras\Dbal\Exceptions\InvalidArgumentException;


class SqlProcessor
{
	/** @var IDriverProvider */
	private $driver;


	public function __construct(IDriver $driver)
	{
		$this->driver = $driver;
	}


	/**
	 * @return string
	 */
	public function process(array $args)
	{
		$last = count($args) - 1;
		$query = '';

		for ($i = 0, $j = 0; $j <= $last; $j++) {
			if (!is_string($args[$j])) {
				throw new InvalidArgumentException($j === 0
					? 'Query fragment must be string.'
					: "Redundant query parameter or missing modifier in query fragment '$args[$i]'."
				);
			}

			$i = $j;
			$query .= ($i ? ' ' : '');
			$query .= preg_replace_callback(
				'#%(\w++\??+(?:\[\])?+)|\[(.+?)\]#', // %modifier | [identifier]
				function ($matches) use ($args, &$j, $last) {
					if ($matches[1] !== '') {
						if ($j === $last) {
							throw new InvalidArgumentException("Missing query parameter for modifier $matches[0].");
						}
						return $this->processValue($args[++$j], $matches[1]);

					} else {
						return $this->driver->convertToSql($matches[2], IDriver::TYPE_IDENTIFIER);
					}
				},
				$args[$i]
			);

			if ($i === $j && $j !== $last) {
{'fraction_non_alphanumeric': 0.19827586206896552, 'fraction_numerical': 0.006551724137931035, 'mean_word_length': 3.0235783633841886, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, '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': '6018667', 'n_tokens_mistral': 1219, 'n_tokens_neox': 982, 'n_words': 232}