<commit_before><?php

namespace mageekguy\atoum\scripts\phar;

use
	mageekguy\atoum,
	mageekguy\atoum\scripts,
	mageekguy\atoum\exceptions
;

class stub extends scripts\runner
{
	const scriptsDirectory = 'scripts';
	const scriptsExtension = '.php';

	public function listScripts()
	{
		$this->writeMessage($this->locale->_('Available scripts are:') . PHP_EOL);
		$this->writeMessage(self::padding . 'builder');
		$this->writeMessage(self::padding . 'tagger');

		$this->runTests = false;

		return $this;
	}

	public function useScript($script)
	{
		switch ($script)
		{
			case 'builder':
			case 'tagger':
				$scriptFile = self::getScriptFile($script);

				if (file_exists($scriptFile) === false)
				{
					throw new exceptions\logic\invalidArgument(sprintf($this->getLocale()->_('Script file %s does not exist for script %s'), $scriptFile, $script));
				}

				require_once $scriptFile;

				exit(0);

			default:
				throw new exceptions\logic\invalidArgument(sprintf($this->getLocale()->_('Script %s does not exist'), $script));
		}
	}

	public function infos()
	{
		$phar = new \phar(\phar::running());

		$this
			->writeMessage($this->locale->_('Informations:') . PHP_EOL)
			->writeLabels($phar->getMetadata())
		;

		$this->runTests = false;

		return $this;
	}

	public function signature()
	{
		$phar = new \phar(\phar::running());

		$signature = $phar->getSignature();

		$this->writeLabel($this->locale->_('Signature'), $signature['hash']);

		$this->runTests = false;

		return $this;
	}

	public function extractTo($directory)
	{
		$phar = new \phar($this->getName());

		try
		{
			$phar->extractTo($directory);
		}
		catch (\exception $exception)
		{
			throw new exceptions\logic('Unable to extract in \'' . $directory . '\'');
		}

		$this->runTests = false;

		return $this;
	}

	public function extractResourcesTo($directory)
	{
		$phar = new \phar($this->getName());

		if (isset($phar['resources']) === false)
		{
			throw new exceptions\logic('Resources directory does not exist in PHAR \'' . $this->getName() . '\'');
		}

		try
		{
			foreach (new \recursiveIteratorIterator(new \recursiveDirectoryIterator($phar['resources'], \filesystemIterator::CURRENT_AS_SELF)) as $resources)
			{
				if ($resources->current()->isFile() === true)
				{
					$phar->extractTo($directory, 'resources/' . $resources->getSubpathname());
				}
			}
		}
		catch (\exception $exception)
		{
			throw new exceptions\logic('Unable to extract resources in \'' . $directory . '\'');
		}

		$this->runTests = false;

		return $this;
	}

	public function includeDefaultConfigFile()
	{
		try
		{
			$this->includeFile(dirname(\phar::running(false)) . '/' . self::defaultConfigFile);
		}
		catch (\exception $exception) {};

		return $this;
	}

	protected function setArgumentHandlers()
	{
		parent::setArgumentHandlers();

		$this->addArgumentHandler(
			function($script, $argument, $values) {
				if (sizeof($values) !== 0)
				{
					throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
				}

				$script->infos();
			},
			array('-i', '--infos'),
			null,
			$this->locale->_('Display informations, do not run any script')
		);

		$this->addArgumentHandler(
			function($script, $argument, $values) {
				if (sizeof($values) !== 0)
				{<commit_msg>Remove bug in default configuration file management in stub.<commit_after><?php

namespace mageekguy\atoum\scripts\phar;

use
	mageekguy\atoum,
	mageekguy\atoum\scripts,
	mageekguy\atoum\exceptions
;

class stub extends scripts\runner
{
	const scriptsDirectory = 'scripts';
	const scriptsExtension = '.php';

	public function listScripts()
	{
		$this->writeMessage($this->locale->_('Available scripts are:') . PHP_EOL);
		$this->writeMessage(self::padding . 'builder');
		$this->writeMessage(self::padding . 'tagger');

		$this->runTests = false;

		return $this;
	}

	public function useScript($script)
	{
		switch ($script)
		{
			case 'builder':
			case 'tagger':
				$scriptFile = self::getScriptFile($script);

				if (file_exists($scriptFile) === false)
				{
					throw new exceptions\logic\invalidArgument(sprintf($this->getLocale()->_('Script file %s does not exist for script %s'), $scriptFile, $script));
				}

				require_once $scriptFile;

				exit(0);

			default:
				throw new exceptions\logic\invalidArgument(sprintf($this->getLocale()->_('Script %s does not exist'), $script));
		}
	}

	public function infos()
	{
		$phar = new \phar(\phar::running());

		$this
			->writeMessage($this->locale->_('Informations:') . PHP_EOL)
			->writeLabels($phar->getMetadata())
		;

		$this->runTests = false;

		return $this;
	}

	public function signature()
	{
		$phar = new \phar(\phar::running());

		$signature = $phar->getSignature();

		$this->writeLabel($this->locale->_('Signature'), $signature['hash']);

		$this->runTests = false;

		return $this;
	}

	public function extractTo($directory)
	{
		$phar = new \phar($this->getName());

		try
		{
			$phar->extractTo($directory);
		}
		catch (\exception $exception)
		{
			throw new exceptions\logic('Unable to extract in \'' . $directory . '\'');
		}

		$this->runTests = false;

		return $this;
	}

	public function extractResourcesTo($directory)
	{
		$phar = new \phar($this->getName());

		if (isset($phar['resources']) === false)
		{
			throw new exceptions\logic('Resources directory does not exist in PHAR \'' . $this->getName() . '\'');
		}

		try
		{
			foreach (new \recursiveIteratorIterator(new \recursiveDirectoryIterator($phar['resources'], \filesystemIterator::CURRENT_AS_SELF)) as $resources)
			{
				if ($resources->current()->isFile() === true)
				{
					$phar->extractTo($directory, 'resources/' . $resources->getSubpathname());
				}
			}
		}
		catch (\exception $exception)
		{
			throw new exceptions\logic('Unable to extract resources in \'' . $directory . '\'');
		}

		$this->runTests = false;

		return $this;
	}

	public function useDefaultConfigFile()
	{
		try
		{
			$this->useConfigFile(dirname(\phar::running(false)) . '/' . self::defaultConfigFile);
		}
		catch (\exception $exception) {};

		return $this;
	}

	protected function setArgumentHandlers()
	{
		parent::setArgumentHandlers();

		$this->addArgumentHandler(
			function($script, $argument, $values) {
				if (sizeof($values) !== 0)
				{
					throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
				}

				$script->infos();
			},
			array('-i', '--infos'),
			null,
			$this->locale->_('Display informations, do not run any script')
		);

		$this->addArgumentHandler(
			function($script, $argument, $values) {
				if (sizeof($values) !== 0)
				{
{'fraction_non_alphanumeric': 0.1755186111519788, 'fraction_numerical': 0.0008827423863469177, 'mean_word_length': 3.821276595744681, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 83, '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': '2462815', 'n_tokens_mistral': 2574, 'n_tokens_neox': 2187, 'n_words': 456}