<commit_before><?php
/**
 * This file is part of the Kappa\DoctrineMPTT package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the license.md
 * file that was distributed with this source code.
 */

namespace KappaTests\DoctrineMPTT;

/**
 * Class SqlLogger
 *
 * @package KappaTests\DoctrineMPTT
 * @author <NAME> <http://zaruba-ondrej.cz>
 */
class SqlLogger implements \Doctrine\DBAL\Logging\SQLLogger
{
	private $queries = [];

	/**
	 * Logs a SQL statement somewhere.
	 *
	 * @param string $sql The SQL to be executed.
	 * @param array|null $params The SQL parameters.
	 * @param array|null $types The SQL parameter types.
	 *
	 * @return void
	 */
	public function startQuery($sql, array $params = null, array $types = null)
	{
		$this->queries[] = $sql;
	}

	/**
	 * Marks the last started query as stopped. This can be used for timing of queries.
	 *
	 * @return void
	 */
	public function stopQuery()
	{

	}

	public function getQueries()
	{
		return $this->queries;
	}
}<commit_msg>Refactored SQLogger now store queries into file<commit_after><?php
/**
 * This file is part of the Kappa\DoctrineMPTT package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the license.md
 * file that was distributed with this source code.
 */

namespace KappaTests\DoctrineMPTT;

/**
 * Class SqlLogger
 *
 * @package KappaTests\DoctrineMPTT
 * @author <NAME> <http://zaruba-ondrej.cz>
 */
class SqlLogger implements \Doctrine\DBAL\Logging\SQLLogger
{
	/** @var array */
	private $queries = [];

	/** @var string */
	private $section = "initialize";

	/** @var string */
	private $directory;

	/**
	 * @param $directory
	 * @throws \Exception
	 */
	public function __construct($directory)
	{
		if (!file_exists($directory)) {
			throw new \Exception("Missing directory");
		}
		$this->directory = $directory;
	}

	/**
	 * Logs a SQL statement somewhere.
	 *
	 * @param string $sql The SQL to be executed.
	 * @param array|null $params The SQL parameters.
	 * @param array|null $types The SQL parameter types.
	 *
	 * @return void
	 */
	public function startQuery($sql, array $params = null, array $types = null)
	{
		if (array_key_exists($this->section, $this->queries)) {
			$this->queries[$this->section][] = $sql;
		} else {
			$this->queries[$this->section] = [$sql];
		}
	}

	/**
	 * Marks the last started query as stopped. This can be used for timing of queries.
	 *
	 * @return void
	 */
	public function stopQuery()
	{
	}

	public function startSection()
	{
		$trace = debug_backtrace();
		$this->section = $trace[1]['function'];
	}

	public function stopSection()
	{
		$content = '';
		foreach ($this->queries[$this->section] as $key => $sql) {
			$content .= $key + 1 . " => " . $sql . PHP_EOL;
		}

		file_put_contents($this->directory . DIRECTORY_SEPARATOR . $this->section . '.log', $content);
	}
}
{'fraction_non_alphanumeric': 0.145912383580545, 'fraction_numerical': 0.0006898930665746809, 'mean_word_length': 3.400606980273141, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, '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': '4929088', 'n_tokens_mistral': 992, 'n_tokens_neox': 928, 'n_words': 279}