<commit_before><?php
/**
 * commands_filter_AddFilter
 * @package modules.filter.command
 */
class commands_filter_AddFilter extends commands_AbstractChangeCommand
{
	/**
	 * @return String
	 * @example "<moduleName> <name>"
	 */
	function getUsage()
	{
		return "<moduleName> <name> <modelName> [<commaSeparatedParamNames>]";
	}

	/**
	 * @return String
	 * @example "initialize a document"
	 */
	function getDescription()
	{
		return "adds a new filter";
	}
	
	/**
	 * @param String[] $params
	 * @param array<String, String> $options where the option array key is the option name, the potential option value or true
	 */
	protected function validateArgs($params, $options)
	{
		return count($params) == 3 || count($params) == 4;
	}

	/**
	 * @return String[]
	 */
//	function getOptions()
//	{
//	}

	/**
	 * @param String[] $params
	 * @param array<String, String> $options where the option array key is the option name, the potential option value or true
	 * @see c_ChangescriptCommand::parseArgs($args)
	 */
	function _execute($params, $options)
	{
		$this->message("== AddFilter ==");

		$this->loadFramework();
		
		$moduleName = strtolower($params[0]);
		$filterName = ucfirst($params[1]);
		$modelName = $params[2];
		$paramNames = isset($params[3]) ? explode(',', $params[3]) : array();
		if (!ModuleService::getInstance()->moduleExists($moduleName))
		{
			return $this->quitError("Component $moduleName does not exits");
		}
		else
		{
			$filterFolder = f_util_FileUtils::buildWebeditPath('modules', $moduleName, 'persistentdocument', 'filters');
			$filterFile = $filterFolder . DIRECTORY_SEPARATOR . $filterName . 'Filter.php';
			$class = $moduleName . '_' . $filterName . 'Filter';
		}
		
		if (file_exists($filterFile))
		{
			return $this->quitError('Filter "' . $filterName . '" already exists in ' . $moduleName . '".');
		}
		
		$generator = new builder_Generator();
		$generator->setTemplateDir(f_util_FileUtils::buildWebeditPath('modules', 'filter', 'templates', 'builder'));
		$generator->assign_by_ref('author', $this->getAuthor());
		$generator->assign_by_ref('name', $filterName);
		$generator->assign_by_ref('module', $moduleName);
		$generator->assign_by_ref('date', date('r'));
		$generator->assign_by_ref('class', $class);
		$generator->assign_by_ref('modelName', $modelName);
		$generator->assign_by_ref('parameters', $paramNames);
		$result = $generator->fetch('filter.tpl');
		
		f_util_FileUtils::mkdir($filterFolder);
		f_util_FileUtils::write($filterFile, $result);
		ClassResolver::getInstance()->appendToAutoloadFile($class, realpath($filterFile));
		$this->message('Filter class path: ' . $filterFile);
		
		// Add locale.
		$filterKey = strtolower($filterName) . 'filter-';
		$baseKey = strtolower('m.' . $moduleName . '.bo.documentfilters');
		$keysInfos = array('fr_FR' => array($filterKey . 'label' => $filterName));
		LocaleService::getInstance()->updatePackage($baseKey, $keysInfos, false, true, '');
		
		$replacementParams = array();
		foreach ($paramNames as $paramName)
		{
			$replacementParams[] = '{'. $paramName . '}';
		}		
		$keysInfos = array('fr_FR' => array($filterKey . 'text' => $filterName . ": " . implode(', ', $replacementParams)));
		LocaleService::getInstance()->updatePackage($baseKey, $keysInfos, false, true, '');
		$this->message('Filter locales in ' . $baseKey . ': ' . $filterKey . 'label' . ' and ' . $filterKey  . 'text');
					
		return $this->quitOk("Command successfully executed");
	}
}<commit_msg>[DOC] Enhance the doc for the PHPDoc<commit_after><?php
/**
 * commands_filter_AddFilter
 * @package modules.filter.command
 */
class commands_filter_AddFilter extends commands_AbstractChangeCommand
{
	/**
	 * @return String
	 */
	function getUsage()
	{
		return "<moduleName> <name> <modelName> [<commaSeparatedParamNames>]";
	}

	/**
	 * @return String
	 */
	function getDescription()
	{
		return "adds a new filter";
	}
	
	/**
	 * @param String[] $params
	 * @param array<String, String> $options where the option array key is the option name, the potential option value or true
	 */
	protected function validateArgs($params, $options)
	{
		return count($params) == 3 || count($params) == 4;
	}

	/**
	 * @return String[]
	 */
//	function getOptions()
//	{
//	}

	/**
	 * @param String[] $params
	 * @param array<String, String> $options where the option array key is the option name, the potential option value or true
	 * @see c_ChangescriptCommand::parseArgs($args)
	 */
	function _execute($params, $options)
	{
		$this->message("== AddFilter ==");

		$this->loadFramework();
		
		$moduleName = strtolower($params[0]);
		$filterName = ucfirst($params[1]);
		$modelName = $params[2];
		$paramNames = isset($params[3]) ? explode(',', $params[3]) : array();
		if (!ModuleService::getInstance()->moduleExists($moduleName))
		{
			return $this->quitError("Component $moduleName does not exits");
		}
		else
		{
			$filterFolder = f_util_FileUtils::buildWebeditPath('modules', $moduleName, 'persistentdocument', 'filters');
			$filterFile = $filterFolder . DIRECTORY_SEPARATOR . $filterName . 'Filter.php';
			$class = $moduleName . '_' . $filterName . 'Filter';
		}
		
		if (file_exists($filterFile))
		{
			return $this->quitError('Filter "' . $filterName . '" already exists in ' . $moduleName . '".');
		}
		
		$generator = new builder_Generator();
		$generator->setTemplateDir(f_util_FileUtils::buildWebeditPath('modules', 'filter', 'templates', 'builder'));
		$generator->assign_by_ref('author', $this->getAuthor());
		$generator->assign_by_ref('name', $filterName);
		$generator->assign_by_ref('module', $moduleName);
		$generator->assign_by_ref('date', date('r'));
		$generator->assign_by_ref('class', $class);
		$generator->assign_by_ref('modelName', $modelName);
		$generator->assign_by_ref('parameters', $paramNames);
		$result = $generator->fetch('filter.tpl');
		
		f_util_FileUtils::mkdir($filterFolder);
		f_util_FileUtils::write($filterFile, $result);
		ClassResolver::getInstance()->appendToAutoloadFile($class, realpath($filterFile));
		$this->message('Filter class path: ' . $filterFile);
		
		// Add locale.
		$filterKey = strtolower($filterName) . 'filter-';
		$baseKey = strtolower('m.' . $moduleName . '.bo.documentfilters');
		$keysInfos = array('fr_FR' => array($filterKey . 'label' => $filterName));
		LocaleService::getInstance()->updatePackage($baseKey, $keysInfos, false, true, '');
		
		$replacementParams = array();
		foreach ($paramNames as $paramName)
		{
			$replacementParams[] = '{'. $paramName . '}';
		}		
		$keysInfos = array('fr_FR' => array($filterKey . 'text' => $filterName . ": " . implode(', ', $replacementParams)));
		LocaleService::getInstance()->updatePackage($baseKey, $keysInfos, false, true, '');
		$this->message('Filter locales in ' . $baseKey . ': ' . $filterKey . 'label' . ' and ' . $filterKey  . 'text');
					
		return $this->quitOk("Command successfully executed");
	}
}
{'fraction_non_alphanumeric': 0.18150238818931827, 'fraction_numerical': 0.002026342451874367, 'mean_word_length': 4.710743801652892, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 67, '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': '2257994', 'n_tokens_mistral': 2382, 'n_tokens_neox': 2159, 'n_words': 445}