<commit_before><?php
/**
 * Фабрика. Содержит алогритм выбора стратегии авторизации
 *
 * @file      UserAuthFactory.php
 *
 * PHP version 5.6+
 *
 * @author    <NAME> <alex at itvault dot info>
 * @copyright © 2012-2016 <NAME> <alex at itvault at info>
 * @date      Вск Янв 27 17:34:29 2013
 * @license   The BSD 3-Clause License
 *            <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>.
 */

namespace Veles\Auth;

use Veles\Auth\Strategies\AbstractAuthStrategy;
use Veles\Auth\Strategies\CookieStrategy;
use Veles\Auth\Strategies\GuestStrategy;
use Veles\Auth\Strategies\LoginFormStrategy;
use Veles\Model\User;

/**
 * Class UserAuthFactory
 *
 * @author  <NAME> <alex at itvault dot info>
 */
class UsrAuthFactory
{
	protected $cookie_definitions = [
		'id' => [
			'filter' => FILTER_VALIDATE_INT,
			'options' => [
				'min_range' => 1,
				'max_range' => PHP_INT_MAX
			]
		],
		'pw' => [
			'filter' => FILTER_VALIDATE_REGEXP,
			'options' => [
				'regexp' => '/^[a-z0-9_.-]{1,20}$/i'
			]
		]
	];
	protected $post_definitions = [
		'ln' => FILTER_VALIDATE_EMAIL,
		'pw' => [
			'filter' => FILTER_VALIDATE_REGEXP,
			'options' => [
				'regexp' => '/^[a-z0-9_-]{1,20}$/i'
			]
		]
	];

	/**
	 * Algorithm for choosing auth strategy
	 *
	 * @todo Move validation and error handling into separate class
	 * @return AbstractAuthStrategy
	 */
	public function create()
	{
		$post    = $this->getPost();
		$cookies = $this->getCookies();

		switch (true) {
			case (isset($post['ln'], $post['pw'])):
				return new LoginFormStrategy(
					$post['ln'], $post['pw'], new User
				);
			case (isset($cookies['id'], $cookies['pw'])):
				return new CookieStrategy(
					$cookies['id'], $cookies['pw'], new User
				);
			default:
				return new GuestStrategy(new User);
		}
	}

	/**
	 * @codeCoverageIgnore
	 * @return mixed
	 */
	protected function getCookies()
	{
		$cookies = filter_input_array(INPUT_COOKIE, $this->cookie_definitions);

		return $cookies;
	}

	/**
	 * @codeCoverageIgnore
	 * @return mixed
	 */
	protected function getPost()
	{
		$post = filter_input_array(INPUT_POST, $this->post_definitions);

		return $post;
	}
}
<commit_msg>Fix authentication error<commit_after><?php
/**
 * Фабрика. Содержит алогритм выбора стратегии авторизации
 *
 * @file      UserAuthFactory.php
 *
 * PHP version 5.6+
 *
 * @author    <NAME> <alex at itvault dot info>
 * @copyright © 2012-2016 <NAME> <alex at itvault at info>
 * @date      Вск Янв 27 17:34:29 2013
 * @license   The BSD 3-Clause License
 *            <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>.
 */

namespace Veles\Auth;

use Veles\Auth\Strategies\AbstractAuthStrategy;
use Veles\Auth\Strategies\CookieStrategy;
use Veles\Auth\Strategies\GuestStrategy;
use Veles\Auth\Strategies\LoginFormStrategy;
use Veles\Model\User;

/**
 * Class UserAuthFactory
 *
 * @author  <NAME> <alex at itvault dot info>
 */
class UsrAuthFactory
{
	protected $cookie_definitions = [
		'id' => [
			'filter' => FILTER_VALIDATE_INT,
			'flags'  => FILTER_NULL_ON_FAILURE,
			'options' => [
				'min_range' => 1,
				'max_range' => PHP_INT_MAX
			]
		],
		'pw' => [
			'filter' => FILTER_VALIDATE_REGEXP,
			'flags'  => FILTER_NULL_ON_FAILURE,
			'options' => [
				'regexp' => '/^.{31}$/'
			]
		]
	];
	protected $post_definitions = [
		'ln' => [
			'filter' => FILTER_VALIDATE_EMAIL,
			'flags'  => FILTER_NULL_ON_FAILURE
		],
		'pw' => [
			'filter' => FILTER_VALIDATE_REGEXP,
			'flags'  => FILTER_NULL_ON_FAILURE,
			'options' => [
				'regexp' => '/^[a-z0-9_-]{1,20}$/i'
			]
		]
	];

	/**
	 * Algorithm for choosing auth strategy
	 *
	 * @todo Move validation and error handling into separate class
	 * @return AbstractAuthStrategy
	 */
	public function create()
	{
		$post    = $this->getPost();
		$cookies = $this->getCookies();

		switch (true) {
			case (isset($post['ln'], $post['pw'])):
				return new LoginFormStrategy(
					$post['ln'], $post['pw'], new User
				);
			case (isset($cookies['id'], $cookies['pw'])):
				return new CookieStrategy(
					$cookies['id'], $cookies['pw'], new User
				);
			default:
				return new GuestStrategy(new User);
		}
	}

	/**
	 * @codeCoverageIgnore
	 * @return mixed
	 */
	protected function getCookies()
	{
		$cookies = filter_input_array(INPUT_COOKIE, $this->cookie_definitions);

		return $cookies;
	}

	/**
	 * @codeCoverageIgnore
	 * @return mixed
	 */
	protected function getPost()
	{
		$post = filter_input_array(INPUT_POST, $this->post_definitions);

		return $post;
	}
}

{'fraction_non_alphanumeric': 0.1619110816191108, 'fraction_numerical': 0.014819730148197301, 'mean_word_length': 3.352261790182868, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 58, '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': '3912958', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1677, 'n_words': 333}