<commit_before><?php

/**
 * This file is part of the Arachne EntityLoader extenstion
 *
 * Copyright (c) <NAME> (<EMAIL>)
 *
 * For the full copyright and license information, please view the file license.md that was distributed with this source code.
 */

namespace Arachne\EntityLoader;

/**
 * @author <NAME>
 */
class EntityLoader extends \Nette\Object
{

	/** @var \Arachne\EntityLoader\ParameterFinder */
	protected $finder;

	/** @var \Arachne\EntityLoader\IConverter */
	protected $converter;

	/**
	 * @param \Arachne\EntityLoader\ParameterFinder $finder
	 * @param \Arachne\EntityLoader\IConverter $converter
	 */
	public function __construct(ParameterFinder $finder, IConverter $converter)
	{
		$this->finder = $finder;
		$this->converter = $converter;
	}

	/**
	 * Replaces scalars in request by entities.
	 * @param \Nette\Application\Request $request
	 * @return bool
	 */
	public function loadEntities(\Nette\Application\Request $request)
	{
		$entities = $this->finder->getEntityParameters($request);
		if (empty($entities)) {
			return $request;
		}

		$parameters = $request->getParameters();
		foreach ($entities as $key => $mapping) {
			if (isset($parameters[$key])) {
				$entity = $this->converter->parameterToEntity($mapping, $parameters[$key]);
				if ($entity === NULL) {
					return FALSE;
				}
				$parameters[$key] = $entity;
			}
		}
		$request->setParameters($parameters);
		return TRUE;
	}

	/**
	 * Replaces entities in request by scalars.
	 * @param \Nette\Application\Request $request
	 * @return bool
	 */
	public function removeEntities(\Nette\Application\Request $request)
	{
		$entities = $this->finder->getEntityParameters($request);
		if (empty($entities)) {
			return $request;
		}

		$parameters = $request->getParameters();
		foreach ($entities as $key => $mapping) {
			if (isset($parameters[$key])) {
				$parameter = $this->converter->entityToParameter($mapping, $parameters[$key]);
				if ($parameter === NULL) {
					return FALSE;
				}<commit_msg>typos<commit_after><?php

/**
 * This file is part of the Arachne EntityLoader extenstion
 *
 * Copyright (c) <NAME> (<EMAIL>)
 *
 * For the full copyright and license information, please view the file license.md that was distributed with this source code.
 */

namespace Arachne\EntityLoader;

/**
 * @author <NAME>
 */
class EntityLoader extends \Nette\Object
{

	/** @var \Arachne\EntityLoader\ParameterFinder */
	protected $finder;

	/** @var \Arachne\EntityLoader\IConverter */
	protected $converter;

	/**
	 * @param \Arachne\EntityLoader\ParameterFinder $finder
	 * @param \Arachne\EntityLoader\IConverter $converter
	 */
	public function __construct(ParameterFinder $finder, IConverter $converter)
	{
		$this->finder = $finder;
		$this->converter = $converter;
	}

	/**
	 * Replaces scalars in request by entities.
	 * @param \Nette\Application\Request $request
	 * @return bool
	 */
	public function loadEntities(\Nette\Application\Request $request)
	{
		$entities = $this->finder->getEntityParameters($request);
		if (empty($entities)) {
			return $request;
		}

		$parameters = $request->getParameters();
		foreach ($entities as $key => $annotation) {
			if (isset($parameters[$key])) {
				$entity = $this->converter->parameterToEntity($annotation, $parameters[$key]);
				if ($entity === NULL) {
					return FALSE;
				}
				$parameters[$key] = $entity;
			}
		}
		$request->setParameters($parameters);
		return TRUE;
	}

	/**
	 * Replaces entities in request by scalars.
	 * @param \Nette\Application\Request $request
	 * @return bool
	 */
	public function removeEntities(\Nette\Application\Request $request)
	{
		$entities = $this->finder->getEntityParameters($request);
		if (empty($entities)) {
			return $request;
		}

		$parameters = $request->getParameters();
		foreach ($entities as $key => $annotation) {
			if (isset($parameters[$key])) {
				$parameter = $this->converter->entityToParameter($annotation, $parameters[$key]);
				if ($parameter === NULL) {
					return FALSE;
				}
{'fraction_non_alphanumeric': 0.14992503748125938, 'fraction_numerical': 0.0, 'mean_word_length': 3.972670807453416, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, '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': '6528471', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1210, 'n_words': 292}