<commit_before><?php
namespace Robo\Task\ApiGen;

use Robo\Contract\CommandInterface;
use Robo\Exception\TaskException;
use Robo\Task\BaseTask;
use Traversable;

/**
 * Executes ApiGen command to generate documentation
 *
 * ``` php
 * <?php
 * // ApiGen Command
 * $this->taskApiGen('./vendor/apigen/apigen.phar')
 *      ->config('./apigen.neon')
 *      ->templateConfig('vendor/apigen/apigen/templates/bootstrap/config.neon')
 *      ->wipeout(true)
 *       ->run();
 * ?>
 * ```
 */
class ApiGen extends BaseTask implements CommandInterface
{
    use \Robo\Common\ExecOneCommand;

    const BOOL_NO = 'no';
    const BOOL_YES = 'yes';

    /**
     * @var string
     */
    protected $command;
	protected $operation = ' generate';

    /**
     * @param null|string $pathToApiGen
     *
     * @throws \Robo\Exception\TaskException
     */
    public function __construct($pathToApiGen = null)
    {
        $this->command = $pathToApiGen;
		$command_parts = [];
		preg_match('/((?:.+)?apigen(?:\.phar)?)( \w+)? ?(.+)?/', $this->command, $command_parts);
		if (count($command_parts) === 3) {
			list($full_command, $this->command, $this->operation) = $command_parts;
		}
		if (count($command_parts) === 4) {
			list($full_command, $this->command, $this->operation, $arg) = $command_parts;
			$this->arg($arg);
		}
        if (!$this->command) {
            $this->command = $this->findExecutablePhar('apigen');
        }
        if (!$this->command) {
            throw new TaskException(__CLASS__, "No apigen installation found");
        }
    }

    /**
     * Pass methods parameters as arguments to executable. Argument values
     * are automatically escaped.
     *
     * @param string|string[] $args
     *
     * @return $this
     */
    public function args($args)
    {
        if (!is_array($args)) {
            $args = func_get_args();
        }
        $args = array_map(function($arg) {
            if (preg_match('/^\w+$/', trim($arg)) === 1) {
                $this->operation = " $arg";
                return null;
            }
            return $arg;
        }, $args);
        $args = array_filter($args);
        $this->arguments .= ' ' . implode(' ', array_map('static::escape', $args));
        return $this;
    }

    /**
     * @param array|Traversable|string $arg a single object or something traversable
     *
     * @return array|Traversable the provided argument if it was already traversable, or the given
     *                           argument returned as a one-element array
     */
    protected static function forceTraversable($arg)
    {
        $traversable = $arg;
        if (!is_array($traversable) && !($traversable instanceof \Traversable)) {
            $traversable = array($traversable);
        }
        return $traversable;
    }<commit_msg>sniff fixes<commit_after><?php
namespace Robo\Task\ApiGen;

use Robo\Contract\CommandInterface;
use Robo\Exception\TaskException;
use Robo\Task\BaseTask;
use Traversable;

/**
 * Executes ApiGen command to generate documentation
 *
 * ``` php
 * <?php
 * // ApiGen Command
 * $this->taskApiGen('./vendor/apigen/apigen.phar')
 *      ->config('./apigen.neon')
 *      ->templateConfig('vendor/apigen/apigen/templates/bootstrap/config.neon')
 *      ->wipeout(true)
 *       ->run();
 * ?>
 * ```
 */
class ApiGen extends BaseTask implements CommandInterface
{
    use \Robo\Common\ExecOneCommand;

    const BOOL_NO = 'no';
    const BOOL_YES = 'yes';

    /**
     * @var string
     */
    protected $command;
    protected $operation = ' generate';

    /**
     * @param null|string $pathToApiGen
     *
     * @throws \Robo\Exception\TaskException
     */
    public function __construct($pathToApiGen = null)
    {
        $this->command = $pathToApiGen;
        $command_parts = [];
        preg_match('/((?:.+)?apigen(?:\.phar)?)( \w+)? ?(.+)?/', $this->command, $command_parts);
        if (count($command_parts) === 3) {
            list($full_command, $this->command, $this->operation) = $command_parts;
        }
        if (count($command_parts) === 4) {
            list($full_command, $this->command, $this->operation, $arg) = $command_parts;
            $this->arg($arg);
        }
        if (!$this->command) {
            $this->command = $this->findExecutablePhar('apigen');
        }
        if (!$this->command) {
            throw new TaskException(__CLASS__, "No apigen installation found");
        }
    }

    /**
     * Pass methods parameters as arguments to executable. Argument values
     * are automatically escaped.
     *
     * @param string|string[] $args
     *
     * @return $this
     */
    public function args($args)
    {
        if (!is_array($args)) {
            $args = func_get_args();
        }
        $args = array_map(function ($arg) {
            if (preg_match('/^\w+$/', trim($arg)) === 1) {
                $this->operation = " $arg";
                return null;
            }
            return $arg;
        }, $args);
        $args = array_filter($args);
        $this->arguments .= ' ' . implode(' ', array_map('static::escape', $args));
        return $this;
    }

    /**
     * @param array|Traversable|string $arg a single object or something traversable
     *
     * @return array|Traversable the provided argument if it was already traversable, or the given
     *                           argument returned as a one-element array
     */
    protected static function forceTraversable($arg)
    {
        $traversable = $arg;
        if (!is_array($traversable) && !($traversable instanceof \Traversable)) {
            $traversable = array($traversable);
        }
        return $traversable;
    }
{'fraction_non_alphanumeric': 0.15495685860186653, 'fraction_numerical': 0.0010565240359218173, 'mean_word_length': 2.266244968372628, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6784717', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1711, 'n_words': 362}