<commit_before><?php
namespace PhpBrew;

use Exception;
use PhpBrew\Exception\OopsException;

class VariantParser
{

    public static function splitVariantValue($str)
    {
        if (strpos($str, '=') !== false) {
            list($name, $val) = explode('=', $str);

            return array($name => $val);
        }

        return array( $str => true );
    }

    public static function parseCommandArguments(array $args, array $inheritedVariants = array())
    {
        $extra = array();

        $enabledVariants = array();
        $disabledVariants = array();

        // split variant strings
        $startExtra = false;
        foreach ($args as $arg) {
            if ($arg === '--') {
                $startExtra = true;
                continue;
            }

            if (! $startExtra) {
                if ($arg[0] === '+' || $arg[0] === '-') {
                    if (substr($arg, 0, 2) === '--') {
                        throw new Exception("Invalid variant option $arg");
                    }

                    $variantStrings = preg_split('#(?=[+-])#', $arg);
                    $variantStrings = array_filter($variantStrings);

                    foreach ($variantStrings as $str) {
                        if ($str[0] == '+') {
                            $a = self::splitVariantValue(substr($str, 1));
                            $enabledVariants = array_merge($enabledVariants, $a);
                        } elseif ($str[0] == '-') {
                            $a = self::splitVariantValue(substr($str, 1));
                            $disabledVariants = array_merge($disabledVariants, $a);
                        } else {
                            throw new OopsException;
                        }
                    }

                } else {
                    throw new Exception("Invalid variant option $arg");
                }
            } else {
                $extra[] = $arg;
            }
        }

        // inherit variants
        if (isset($inheritedVariants['enabled_variants'])
            && is_array($inheritedVariants['enabled_variants'])
        ) {
            $enabledVariants = array_merge(
                $inheritedVariants['enabled_variants'],
                $enabledVariants
            );
        }

        if (isset($inheritedVariants['disabled_variants'])
            && is_array($inheritedVariants['disabled_variants'])
        ) {
            $disabledVariants = array_merge(
                $inheritedVariants['disabled_variants'],
                $disabledVariants
            );
        }

        if (isset($inheritedVariants['extra_options'])
            && is_array($inheritedVariants['extra_options'])
        ) {
            $extra = array_merge(
                $inheritedVariants['extra_options'],
                $extra
            );
        }
        return array(
            'enabled_variants' => $enabledVariants,
            'disabled_variants' => $disabledVariants,
            'extra_options' => $extra,
        );
    }

    public static function revealCommandArguments($info)
    {<commit_msg>Since we've simplify the variant resolver, we can now remove the code of handling inheritedVariants<commit_after><?php
namespace PhpBrew;

use Exception;
use PhpBrew\Exception\OopsException;

class VariantParser
{

    public static function splitVariantValue($str)
    {
        if (strpos($str, '=') !== false) {
            list($name, $val) = explode('=', $str);

            return array($name => $val);
        }

        return array( $str => true );
    }

    public static function parseCommandArguments(array $args)
    {
        $extra = array();

        $enabledVariants = array();
        $disabledVariants = array();

        // split variant strings
        $startExtra = false;
        foreach ($args as $arg) {
            if ($arg === '--') {
                $startExtra = true;
                continue;
            }

            if (! $startExtra) {
                if ($arg[0] === '+' || $arg[0] === '-') {
                    if (substr($arg, 0, 2) === '--') {
                        throw new Exception("Invalid variant option $arg");
                    }

                    $variantStrings = preg_split('#(?=[+-])#', $arg);
                    $variantStrings = array_filter($variantStrings);

                    foreach ($variantStrings as $str) {
                        if ($str[0] == '+') {
                            $a = self::splitVariantValue(substr($str, 1));
                            $enabledVariants = array_merge($enabledVariants, $a);
                        } elseif ($str[0] == '-') {
                            $a = self::splitVariantValue(substr($str, 1));
                            $disabledVariants = array_merge($disabledVariants, $a);
                        } else {
                            throw new OopsException;
                        }
                    }

                } else {
                    throw new Exception("Invalid variant option $arg");
                }
            } else {
                $extra[] = $arg;
            }
        }
        return array(
            'enabled_variants' => $enabledVariants,
            'disabled_variants' => $disabledVariants,
            'extra_options' => $extra,
        );
    }

    public static function revealCommandArguments($info)
    {
{'fraction_non_alphanumeric': 0.12860599292760097, 'fraction_numerical': 0.00297785222408338, 'mean_word_length': 1.3842058562555457, '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': '5423793', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1317, 'n_words': 276}