<commit_before><?php

namespace ParameterParser;

use Closure;
use Bramus\Ansi\ControlSequences\EscapeSequences\Enums\SGR;

class ParameterCluster
{
    /**
     * The prefixes and the closures associated therewith.
     *
     * @var array
     */
    public $prefixes = [];

    /**
     * The default closure to fall back on when no prefix is found
     * for the argument being parsed.
     *
     * @var Closure
     */
    public $default = null;

    /**
     * Construct the Parameter Cluster and assign a default value to the
     * fall back closure.
     */
    public function __construct()
    {
        $this->default = function ($parameter) {
            return -1;
        };
    }

    /**
     * Add a parameter closure.
     *
     * @param ParameterClosure $closure
     *
     * @return ParameterCluster
     */
    public function add(ParameterClosure $closure)
    {
        $this->prefixes[$closure->prefix][$closure->parameterName] = $closure;

        return $this;
    }

    /**
     * Remove a parameter closure based on prefix and parameter name.
     *
     * @param  string $prefix
     * @param  string $parameterName
     *
     * @return ParameterCluster
     */
    public function remove($prefix, $parameterName)
    {
        unset($this->prefixes[$prefix][$parameterName]);

        return $this;
    }

    /**
     * Add an array of parameters.
     *
     * @param string $prefix
     * @param array  $parameters
     *
     * @return ParameterCluster
     */
    public function addMany($parameters)
    {
        foreach ($parameters as $parameter) {
            $this->prefixes[$parameter->prefix][
                $parameter->parameterName
            ] = $parameter;
        }

        return $this;
    }

    /**
     * Set the default fall back closure.
     *
     * @param Closure $closure
     *
     * @return ParameterCluster
     */
    public function setDefault(Closure $closure)
    {
        $this->default = $closure;

        return $this;
    }

    /**
     * Retrieves the full usage of the ParameterCluster as a string.
     *
     * @param string $showRequiredFirst
     * @param string $customBinary
     * @param string $customScript
     *
     * @return string
     */
    public function getUsage(
        $showRequiredFirst = true,
        $customBinary = null,
        $customScript = null
    ) {
        $fullUsage = '';

        if ($customBinary == null) {
            $fullUsage = 'php ';
        } else {
            $fullUsage = $customBinary.' ';
        }

        if ($customScript == null) {
            $fullUsage .= basename($_SERVER['SCRIPT_NAME']).' ';
        } else {
            $fullUsage .= $customScript.' ';
        }

        foreach ($this->prefixes as $prefix => $parameters) {
            if ($showRequiredFirst) {
                usort($parameters, function ($p1, $p2) {
                    if ($p1->required && $p2->required) {
                        return 0;
                    }

                    if ($p1->required && ! $p2->required) {
                        return -1;
                    }

                    if ($p2->required && ! $p1->required) {
                        return 1;
                    }
                });
            }

            foreach ($parameters as $parameter) {
                if ($parameter->parent == null) {
                    $fullUsage .= $parameter->getUsage().' ';
                }
            }
        }

        return $fullUsage;
    }

    /**
     * Print the full usage along with each commands
     * individual usage and descripition.
     *
     * @param string $applicationName
     * @param string $description
     * @param string $applicationVersion
     * @param bool   $showRequiredFirst
     * @param string $customBinary
     * @param string $customScript
     * @param int    $columnPadding
     */
    public function printFullUsage(
        $applicationName,
        $description = null,
        $applicationVersion = null,
        $showRequiredFirst = true,
        $customBinary = null,
        $customScript = null,
        $columnPadding = 5
    ) {
        // Create Ansi Instance
        $ansi = new \Bramus\Ansi\Ansi();

        $ansi->color([SGR::COLOR_FG_BLUE_BRIGHT])
             ->bold()
             ->text(PHP_EOL.$applicationName)
             ->noStyle();

            
        $ansi->text(
            ($applicationVersion !== null ? ' '.$applicationVersion : '').PHP_EOL
        );
        echo PHP_EOL;

        if ($description != null) {
            $ansi->color([SGR::COLOR_FG_BLUE_BRIGHT])
                 ->bold()
                 ->text('Description:')
                 ->noStyle();
            echo PHP_EOL.PHP_EOL."\t".$description.PHP_EOL.PHP_EOL;
        }<commit_msg>Fixed Style CI: Stage 3<commit_after><?php

namespace ParameterParser;

use Closure;
use Bramus\Ansi\ControlSequences\EscapeSequences\Enums\SGR;

class ParameterCluster
{
    /**
     * The prefixes and the closures associated therewith.
     *
     * @var array
     */
    public $prefixes = [];

    /**
     * The default closure to fall back on when no prefix is found
     * for the argument being parsed.
     *
     * @var Closure
     */
    public $default = null;

    /**
     * Construct the Parameter Cluster and assign a default value to the
     * fall back closure.
     */
    public function __construct()
    {
        $this->default = function ($parameter) {
            return -1;
        };
    }

    /**
     * Add a parameter closure.
     *
     * @param ParameterClosure $closure
     *
     * @return ParameterCluster
     */
    public function add(ParameterClosure $closure)
    {
        $this->prefixes[$closure->prefix][$closure->parameterName] = $closure;

        return $this;
    }

    /**
     * Remove a parameter closure based on prefix and parameter name.
     *
     * @param  string $prefix
     * @param  string $parameterName
     *
     * @return ParameterCluster
     */
    public function remove($prefix, $parameterName)
    {
        unset($this->prefixes[$prefix][$parameterName]);

        return $this;
    }

    /**
     * Add an array of parameters.
     *
     * @param string $prefix
     * @param array  $parameters
     *
     * @return ParameterCluster
     */
    public function addMany($parameters)
    {
        foreach ($parameters as $parameter) {
            $this->prefixes[$parameter->prefix][
                $parameter->parameterName
            ] = $parameter;
        }

        return $this;
    }

    /**
     * Set the default fall back closure.
     *
     * @param Closure $closure
     *
     * @return ParameterCluster
     */
    public function setDefault(Closure $closure)
    {
        $this->default = $closure;

        return $this;
    }

    /**
     * Retrieves the full usage of the ParameterCluster as a string.
     *
     * @param string $showRequiredFirst
     * @param string $customBinary
     * @param string $customScript
     *
     * @return string
     */
    public function getUsage(
        $showRequiredFirst = true,
        $customBinary = null,
        $customScript = null
    ) {
        $fullUsage = '';

        if ($customBinary == null) {
            $fullUsage = 'php ';
        } else {
            $fullUsage = $customBinary.' ';
        }

        if ($customScript == null) {
            $fullUsage .= basename($_SERVER['SCRIPT_NAME']).' ';
        } else {
            $fullUsage .= $customScript.' ';
        }

        foreach ($this->prefixes as $prefix => $parameters) {
            if ($showRequiredFirst) {
                usort($parameters, function ($p1, $p2) {
                    if ($p1->required && $p2->required) {
                        return 0;
                    }

                    if ($p1->required && ! $p2->required) {
                        return -1;
                    }

                    if ($p2->required && ! $p1->required) {
                        return 1;
                    }
                });
            }

            foreach ($parameters as $parameter) {
                if ($parameter->parent == null) {
                    $fullUsage .= $parameter->getUsage().' ';
                }
            }
        }

        return $fullUsage;
    }

    /**
     * Print the full usage along with each commands
     * individual usage and descripition.
     *
     * @param string $applicationName
     * @param string $description
     * @param string $applicationVersion
     * @param bool   $showRequiredFirst
     * @param string $customBinary
     * @param string $customScript
     * @param int    $columnPadding
     */
    public function printFullUsage(
        $applicationName,
        $description = null,
        $applicationVersion = null,
        $showRequiredFirst = true,
        $customBinary = null,
        $customScript = null,
        $columnPadding = 5
    ) {
        // Create Ansi Instance
        $ansi = new \Bramus\Ansi\Ansi();

        $ansi->color([SGR::COLOR_FG_BLUE_BRIGHT])
             ->bold()
             ->text(PHP_EOL.$applicationName)
             ->noStyle();

        $ansi->text(
            ($applicationVersion !== null ? ' '.$applicationVersion : '').PHP_EOL
        );
        echo PHP_EOL;

        if ($description != null) {
            $ansi->color([SGR::COLOR_FG_BLUE_BRIGHT])
                 ->bold()
                 ->text('Description:')
                 ->noStyle();
            echo PHP_EOL.PHP_EOL."\t".$description.PHP_EOL.PHP_EOL;
        }
{'fraction_non_alphanumeric': 0.1160012574662056, 'fraction_numerical': 0.0028292989625903803, 'mean_word_length': 1.5642127888232134, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, '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': '3940853', 'n_tokens_mistral': 2656, 'n_tokens_neox': 2552, 'n_words': 622}