<commit_before><?php

namespace CommerceGuys\Platform\Cli\Helper;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputInterface;

class ArgvHelper extends Helper
{

    public function getName()
    {
        return 'argv';
    }

    /**
     * @param Command $command
     * @param ArgvInput $input
     * @param array $args
     *
     * @return string
     */
    public function getPassedCommand(Command $command, ArgvInput $input, array $args = null)
    {
        if ($args === null) {
            $args = $_SERVER['argv'];
        }
        $args = $this->stripArguments($args, $input);
        $args = $this->stripOptions($args, $command);
        // Escape arguments individually, if there is more than one. If there
        // was just one argument, it indicates that the user passed an entire
        // command inside quotes.
        if (count($args) > 1) {
            $args = array_map(array($this, 'escapeArg'), $args);
        }
        $command = implode(' ', $args);
        return $command;
    }

    /**
     * @param string $arg
     * @return string
     */
    protected function escapeArg($arg)
    {
        // Get a blank ArgvInput object so we can use the 'escapeToken' method.
        $argv = new ArgvInput();
        // If the string contains '=', expand it into the option and value.
        if (strpos($arg, '=')) {
            list($option, $value) = explode('=', $arg, 2);
            return $option . '=' . $argv->escapeToken($value);
        }
        if (strpos($arg, '-') === 0) {
            return $arg;
        }
        return $argv->escapeToken($arg);
    }

    /**
     * @param string[] $args
     * @param InputInterface $input
     *
     * @return string[]
     */
    protected function stripArguments(array $args, InputInterface $input)
    {
        // Strip out the application name.<commit_msg>Accommodate drush/ssh commands containing an = character.<commit_after><?php

namespace CommerceGuys\Platform\Cli\Helper;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputInterface;

class ArgvHelper extends Helper
{

    public function getName()
    {
        return 'argv';
    }

    /**
     * @param Command $command
     * @param ArgvInput $input
     * @param array $args
     *
     * @return string
     */
    public function getPassedCommand(Command $command, ArgvInput $input, array $args = null)
    {
        if ($args === null) {
            $args = $_SERVER['argv'];
        }
        $args = $this->stripArguments($args, $input);
        $args = $this->stripOptions($args, $command);
        // Escape arguments individually, if there is more than one. If there
        // was just one argument, it indicates that the user passed an entire
        // command inside quotes.
        if (count($args) > 1) {
            $args = array_map(array($this, 'escapeArg'), $args);
        }
        $command = implode(' ', $args);
        return $command;
    }

    /**
     * @param string $arg
     * @return string
     */
    protected function escapeArg($arg)
    {
        // Get a blank ArgvInput object so we can use the 'escapeToken' method.
        $argv = new ArgvInput();
        // If the string contains '=', and the part before the '=' could be an
        // option name, expand it into the option and value.
        if (strpos($arg, '=')) {
            list($option, $value) = explode('=', $arg, 2);
            if (preg_match('{^[\w-]+$}', $option)) {
                return $option . '=' . $argv->escapeToken($value);
            }
        }
        if (strpos($arg, '-') === 0) {
            return $arg;
        }
        return $argv->escapeToken($arg);
    }

    /**
     * @param string[] $args
     * @param InputInterface $input
     *
     * @return string[]
     */
    protected function stripArguments(array $args, InputInterface $input)
    {
        // Strip out the application name.
{'fraction_non_alphanumeric': 0.13494558645707377, 'fraction_numerical': 0.0014510278113663846, 'mean_word_length': 2.142857142857143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '3594549', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1173, 'n_words': 335}