<commit_before><?php

/*
	WildPHP - a modular and easily extendable IRC bot written in PHP
	Copyright (C) 2016 WildPHP

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

namespace WildPHP\Core\Permissions;

use WildPHP\Core\Logger\Logger;

class PermissionCriteria
{
	/**
	 * @var string
	 */
	protected $accountName = '';
	/**
	 * @var string
	 */
	protected $channel = '';
	/**
	 * @var string
	 */
	protected $mode = '';

	public function __construct(string $accountName = null, string $channel = null, string $mode = '')
	{
		$this->setAccountName($accountName);
		$this->setChannel($channel);
		$this->setMode($mode);
	}

	/**
	 * @param string $accountName
	 * @return bool
	 */
	public function matchAccountName(string $accountName): bool
	{
		if (empty($this->getAccountName()))
			return true;

		return $this->getAccountName() == $accountName;
	}

	/**
	 * @param string $channel
	 * @return bool
	 */
	public function matchChannel(string $channel): bool
	{
		if (empty($this->getChannel()))
			return true;

		return $this->getChannel() == $channel;
	}

	/**
	 * @param string $mode
	 * @return bool
	 */
	public function matchSingleMode(string $mode): bool
	{
		if (empty($this->getMode()))
			return true;

		return $this->getMode() == $mode;
	}

	/**
	 * @param array $modes
	 * @return bool
	 */
	public function matchMultipleModes(array $modes): bool
	{
		if (empty($this->getMode()))
			return true;

		return in_array($this->getMode(), $modes);
	}

	/**
	 * @param string $accountName
	 * @param string $channel
	 * @param array|string $modes
	 * @return bool
	 */
	public function match(string $accountName = '', string $channel = '', $modes = []): bool
	{
		Logger::debug('Matching permission criteria', [
			'expectedAccountName' => $this->getAccountName(),
			'acquiredAccountName' => $accountName,
			'expectedChannel' => $this->getChannel(),
			'acquiredChannel' => $channel,
			'expectedMode' => $this->getMode(),
			'acquiredMode' => $modes,
			'multipleModes' => is_array($modes)
		]);
		$accountNameMatched = $this->matchAccountName($accountName);
		$channelMatched = $this->matchChannel($channel);
		
		if (is_array($modes))
			$modeMatched = $this->matchMultipleModes($modes);
		else
			$modeMatched = $this->matchSingleMode($modes);
		
		return $accountNameMatched && $modeMatched && $channelMatched;
	}

	/**
	 * @return string
	 */
	public function getMode(): string
	{
		return $this->mode;
	}

	/**
	 * @param string $mode
	 */
	public function setMode(string $mode)
	{
		$this->mode = $mode;
	}

	/**
	 * @return string
	 */
	public function getChannel(): string
	{
		return $this->channel;
	}

	/**
	 * @param string $channel
	 */
	public function setChannel(string $channel)
	{
		$this->channel = $channel;
	}

	/**
	 * @return string
	 */
	public function getAccountName(): string
	{
		return $this->accountName;
	}

	/**
	 * @param string $accountName
	 */
	public function setAccountName(string $accountName)
	{
		$this->accountName = $accountName;
	}

}<commit_msg>null does not match up with string; default to empty strings instead<commit_after><?php

/*
	WildPHP - a modular and easily extendable IRC bot written in PHP
	Copyright (C) 2016 WildPHP

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

namespace WildPHP\Core\Permissions;

use WildPHP\Core\Logger\Logger;

class PermissionCriteria
{
	/**
	 * @var string
	 */
	protected $accountName = '';
	/**
	 * @var string
	 */
	protected $channel = '';
	/**
	 * @var string
	 */
	protected $mode = '';

	public function __construct(string $accountName = '', string $channel = '', string $mode = '')
	{
		$this->setAccountName($accountName);
		$this->setChannel($channel);
		$this->setMode($mode);
	}

	/**
	 * @param string $accountName
	 * @return bool
	 */
	public function matchAccountName(string $accountName): bool
	{
		if (empty($this->getAccountName()))
			return true;

		return $this->getAccountName() == $accountName;
	}

	/**
	 * @param string $channel
	 * @return bool
	 */
	public function matchChannel(string $channel): bool
	{
		if (empty($this->getChannel()))
			return true;

		return $this->getChannel() == $channel;
	}

	/**
	 * @param string $mode
	 * @return bool
	 */
	public function matchSingleMode(string $mode): bool
	{
		if (empty($this->getMode()))
			return true;

		return $this->getMode() == $mode;
	}

	/**
	 * @param array $modes
	 * @return bool
	 */
	public function matchMultipleModes(array $modes): bool
	{
		if (empty($this->getMode()))
			return true;

		return in_array($this->getMode(), $modes);
	}

	/**
	 * @param string $accountName
	 * @param string $channel
	 * @param array|string $modes
	 * @return bool
	 */
	public function match(string $accountName = '', string $channel = '', $modes = []): bool
	{
		Logger::debug('Matching permission criteria', [
			'expectedAccountName' => $this->getAccountName(),
			'acquiredAccountName' => $accountName,
			'expectedChannel' => $this->getChannel(),
			'acquiredChannel' => $channel,
			'expectedMode' => $this->getMode(),
			'acquiredMode' => $modes,
			'multipleModes' => is_array($modes)
		]);
		$accountNameMatched = $this->matchAccountName($accountName);
		$channelMatched = $this->matchChannel($channel);
		
		if (is_array($modes))
			$modeMatched = $this->matchMultipleModes($modes);
		else
			$modeMatched = $this->matchSingleMode($modes);
		
		return $accountNameMatched && $modeMatched && $channelMatched;
	}

	/**
	 * @return string
	 */
	public function getMode(): string
	{
		return $this->mode;
	}

	/**
	 * @param string $mode
	 */
	public function setMode(string $mode)
	{
		$this->mode = $mode;
	}

	/**
	 * @return string
	 */
	public function getChannel(): string
	{
		return $this->channel;
	}

	/**
	 * @param string $channel
	 */
	public function setChannel(string $channel)
	{
		$this->channel = $channel;
	}

	/**
	 * @return string
	 */
	public function getAccountName(): string
	{
		return $this->accountName;
	}

	/**
	 * @param string $accountName
	 */
	public function setAccountName(string $accountName)
	{
		$this->accountName = $accountName;
	}
}
{'fraction_non_alphanumeric': 0.14232261640798227, 'fraction_numerical': 0.001385809312638581, 'mean_word_length': 3.7386736703873935, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7135359', 'n_tokens_mistral': 2450, 'n_tokens_neox': 2184, 'n_words': 641}