<commit_before><?php
namespace Consolidation\AnnotationCommand;

use phpDocumentor\Reflection\DocBlock\Tag\ParamTag;
use phpDocumentor\Reflection\DocBlock;

/**
 * Given a class and method name, parse the annotations in the
 * DocBlock comment, and provide accessor methods for all of
 * the elements that are needed to create a Symfony Console Command.
 */
class CommandInfo
{
    const PARAM_IS_REQUIRED = '__param_is_required__';

    /**
     * @var \ReflectionMethod
     */
    protected $reflection;

    /**
     * @var boolean
     */
    protected $docBlockIsParsed;

    /**
     * @var string
     */
    protected $description = '';

    /**
     * @var string
     */
    protected $help = '';

    /**
     * @var array
     */
    protected $tagProcessors = [
        'param' => 'processArgumentTag',
        'option' => 'processOptionTag',
        'aliases' => 'processAliases',
        'usage' => 'processUsageTag',
        'description' => 'processAlternateDescriptionTag',
        'desc' => 'processAlternateDescriptionTag',
    ];

    /**
     * @var array
     */
    protected $arguments = null;

    /**
     * @var array
     */
    protected $argumentDescriptions = [];

    /**
     * @var array
     */
    protected $optionDescriptions = [];

    /**
     * @var array
     */
    protected $exampleUsage = [];

    /**
     * @var array
     */
    protected $otherAnnotations = [];

    /**
     * @var array
     */
    protected $aliases = [];

    /**
     * @var string
     */
    protected $methodName;

    public function __construct($classNameOrInstance, $methodName)
    {
        $this->reflection = new \ReflectionMethod($classNameOrInstance, $methodName);
        $this->methodName = $methodName;
    }

    public function getMethodName()
    {
        return $this->methodName;
    }

    /**
     * Get the synopsis of the command (~first line).
     */
    public function getDescription()
    {
        $this->parseDocBlock();
        return $this->description;
    }

    public function setDescription($description)
    {
        $this->description = $description;
    }

    /**
     * Get the help text of the command (the description)
     */
    public function getHelp()
    {
        $this->parseDocBlock();
        return $this->help;
    }

    public function setHelp($help)
    {
        $this->help = $help;
    }

    public function getAliases()
    {
        return $this->aliases;
    }

    public function setAliases($aliases)
    {
        if (is_string($aliases)) {
            $aliases = explode(',', static::convertListToCommaSeparated($aliases));
        }
        $this->aliases = array_filter($aliases);
    }

    public function getExampleUsages()
    {
        return $this->exampleUsage;
    }

    public function getName()
    {
        $name = $this->getAnnotation('name');
        if (!$name) {
            $name = $this->reflection->name;
        }
        $name = $this->convertName($name);
        return $name;
    }

    public function calculateAgumentCache()
    {
        $args = [];
        $params = $this->reflection->getParameters();
        if (!empty($this->getOptions())) {
            array_pop($params);
        }
        foreach ($params as $param) {
            $val = $this->getArgumentDefaultValue($param);
            if ($val !== false) {
                $args[$param->name] = $val;
            }
        }
        return $args;
    }

    public function getArguments()
    {
        if (!$this->arguments) {
            $this->arguments = $this->calculateAgumentCache();
        }
        return $this->arguments;
    }

    protected function getArgumentDefaultValue($param)
    {
        // arrays are array arguments
        if (!$param->isArray()) {
            if ($param->isDefaultValueAvailable()) {
                return $param->getDefaultValue();
            }
            return null;
        }
        if (!$param->isDefaultValueAvailable()) {
            return [];
        }
        if (!$this->isAssoc($param->getDefaultValue())) {
            return $param->getDefaultValue();
        }
        return false;
    }

    public function getOptions()
    {
        $params = $this->reflection->getParameters();
        if (empty($params)) {<commit_msg>Always treat CommandInfo:: as an array (don't use null).<commit_after><?php
namespace Consolidation\AnnotationCommand;

use phpDocumentor\Reflection\DocBlock\Tag\ParamTag;
use phpDocumentor\Reflection\DocBlock;

/**
 * Given a class and method name, parse the annotations in the
 * DocBlock comment, and provide accessor methods for all of
 * the elements that are needed to create a Symfony Console Command.
 */
class CommandInfo
{
    const PARAM_IS_REQUIRED = '__param_is_required__';

    /**
     * @var \ReflectionMethod
     */
    protected $reflection;

    /**
     * @var boolean
     */
    protected $docBlockIsParsed;

    /**
     * @var string
     */
    protected $description = '';

    /**
     * @var string
     */
    protected $help = '';

    /**
     * @var array
     */
    protected $tagProcessors = [
        'param' => 'processArgumentTag',
        'option' => 'processOptionTag',
        'aliases' => 'processAliases',
        'usage' => 'processUsageTag',
        'description' => 'processAlternateDescriptionTag',
        'desc' => 'processAlternateDescriptionTag',
    ];

    /**
     * @var array
     */
    protected $arguments = [];

    /**
     * @var array
     */
    protected $argumentDescriptions = [];

    /**
     * @var array
     */
    protected $optionDescriptions = [];

    /**
     * @var array
     */
    protected $exampleUsage = [];

    /**
     * @var array
     */
    protected $otherAnnotations = [];

    /**
     * @var array
     */
    protected $aliases = [];

    /**
     * @var string
     */
    protected $methodName;

    public function __construct($classNameOrInstance, $methodName)
    {
        $this->reflection = new \ReflectionMethod($classNameOrInstance, $methodName);
        $this->methodName = $methodName;
        $this->arguments = $this->calculateAgumentCache();
    }

    public function getMethodName()
    {
        return $this->methodName;
    }

    /**
     * Get the synopsis of the command (~first line).
     */
    public function getDescription()
    {
        $this->parseDocBlock();
        return $this->description;
    }

    public function setDescription($description)
    {
        $this->description = $description;
    }

    /**
     * Get the help text of the command (the description)
     */
    public function getHelp()
    {
        $this->parseDocBlock();
        return $this->help;
    }

    public function setHelp($help)
    {
        $this->help = $help;
    }

    public function getAliases()
    {
        return $this->aliases;
    }

    public function setAliases($aliases)
    {
        if (is_string($aliases)) {
            $aliases = explode(',', static::convertListToCommaSeparated($aliases));
        }
        $this->aliases = array_filter($aliases);
    }

    public function getExampleUsages()
    {
        return $this->exampleUsage;
    }

    public function getName()
    {
        $name = $this->getAnnotation('name');
        if (!$name) {
            $name = $this->reflection->name;
        }
        $name = $this->convertName($name);
        return $name;
    }

    protected function calculateAgumentCache()
    {
        $args = [];
        $params = $this->reflection->getParameters();
        if (!empty($this->getOptions())) {
            array_pop($params);
        }
        foreach ($params as $param) {
            $val = $this->getArgumentDefaultValue($param);
            if ($val !== false) {
                $args[$param->name] = $val;
            }
        }
        return $args;
    }

    public function getArguments()
    {
        return $this->arguments;
    }

    protected function getArgumentDefaultValue($param)
    {
        // arrays are array arguments
        if (!$param->isArray()) {
            if ($param->isDefaultValueAvailable()) {
                return $param->getDefaultValue();
            }
            return null;
        }
        if (!$param->isDefaultValueAvailable()) {
            return [];
        }
        if (!$this->isAssoc($param->getDefaultValue())) {
            return $param->getDefaultValue();
        }
        return false;
    }

    public function getOptions()
    {
        $params = $this->reflection->getParameters();
        if (empty($params)) {
{'fraction_non_alphanumeric': 0.13525213525213525, 'fraction_numerical': 0.0, 'mean_word_length': 1.9567623659633344, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 82, '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': '5749767', 'n_tokens_mistral': 2405, 'n_tokens_neox': 2357, 'n_words': 511}