<commit_before><?php

abstract class Tools
{
    /**
     * Contains classmap from composer
     * @var array
     */
    private $classMap = array();

    /**
     * Returns the classMap from composer.
     * Fetch it from the command dump-autoload if needed
     * @param bool $force Force to fetch it from the command
     * @return array
     */
    protected function getClassMap($force = false)
    {
        if (empty($this->classMap) || $force) {
            if (Config::get('classmap_file') && !file_exists(Config::get('classmap_file')) || $force) {
                // Check if composer is executable or not
                if (is_executable(Config::get('composer'))) {
                    exec(sprintf('%s dump-autoload --optimize --quiet --no-interaction --working-dir=%s 2>&1',
                        escapeshellarg(Config::get('composer')),
                        escapeshellarg(Config::get('projectPath'))
                    ));
                } else {
                    exec(sprintf('%s %s dump-autoload --optimize --quiet --no-interaction --working-dir=%s 2>&1',
                        escapeshellarg(Config::get('php')),
                        escapeshellarg(Config::get('composer')),
                        escapeshellarg(Config::get('projectPath'))
                    ));
                }
            }

            if (Config::get('classmap_file')) {
                $this->classMap = require(Config::get('classmap_file'));
            }
        }

        return $this->classMap;
    }

    /**
     * Format parameters for the autocomplete plugin
     * @param ReflectionMethod $method    Method to get arguments from
     * @param string           $className Class name to use (optional for the moment)
     * @return array
     */
    protected function getMethodArguments($method, $className = null)
    {
        $args = $method->getParameters();
        $optionals = array();
        $parameters = array();

        foreach ($args as $argument) {
            $value = '$' . $argument->getName();

            if ($argument->isPassedByReference()) {
                $value = '&' . $value;
            }

            if ($argument->isOptional()) {
                $optionals[] = $value;
            } else {
                $parameters[] = $value;
            }
        }

        if ($className) {
            $parser = new DocParser();
            $return = $parser->get($className, 'method', $method->getName(), array(DocParser::RETURN_VALUE));
            $descriptions = $parser->get($className, 'method', $method->getName(), array(DocParser::DESCRIPTION));
        }

        return array(
            'parameters' => $parameters,
            'optionals' => $optionals,
            'return'    => ($className && !empty($return)) ? $return['return'] : '',
            'descriptions' => ($className && $descriptions) ? $descriptions['descriptions'] : array()
        );
    }

    /**
     * Returns methods and properties of the given className
     * @param string $className Full namespace of the parsed class
     */
    protected function getClassMetadata($className)
    {
        $data = array(
            'class'  => $className,
            'names'  => array(),
            'values' => array()
        );

        try {
            $reflection = new ReflectionClass($className);
        } catch (Exception $e) {
            return $data;
        }

        $methods    = $reflection->getMethods();
        $attributes = $reflection->getProperties();

        // Methods
        foreach ($methods as $method) {
            $data['names'][] = $method->getName();

            $args = $this->getMethodArguments($method, $className);

            $data['values'][$method->getName()] = array(
                'isMethod'       => true,
                'isPublic'       => $method->isPublic(),
                'isProtected'    => $method->isProtected(),
                'args'           => $args,
                'declaringClass' => $method->getDeclaringClass()->name,
                'startLine'      => $method->getStartLine()
            );
        }

        // Properties
        foreach ($attributes as $attribute) {
            if (!in_array($attribute->getName(), $data['names'])) {
                $data['names'][] = $attribute->getName();
                $data['values'][$attribute->getName()] = null;
            }

            $parser = new DocParser();
            $return = $parser->get($className, 'property', $attribute->getName(), array(DocParser::VAR_TYPE));
            $descriptions = $parser->get($className, 'property', $attribute->getName(), array(DocParser::DESCRIPTION));

            $attributesValues = array(<commit_msg>Fixes #63 wasn't pulling in the trait methods<commit_after><?php

abstract class Tools
{
    /**
     * Contains classmap from composer
     * @var array
     */
    private $classMap = array();

    /**
     * Returns the classMap from composer.
     * Fetch it from the command dump-autoload if needed
     * @param bool $force Force to fetch it from the command
     * @return array
     */
    protected function getClassMap($force = false)
    {
        if (empty($this->classMap) || $force) {
            if (Config::get('classmap_file') && !file_exists(Config::get('classmap_file')) || $force) {
                // Check if composer is executable or not
                if (is_executable(Config::get('composer'))) {
                    exec(sprintf('%s dump-autoload --optimize --quiet --no-interaction --working-dir=%s 2>&1',
                        escapeshellarg(Config::get('composer')),
                        escapeshellarg(Config::get('projectPath'))
                    ));
                } else {
                    exec(sprintf('%s %s dump-autoload --optimize --quiet --no-interaction --working-dir=%s 2>&1',
                        escapeshellarg(Config::get('php')),
                        escapeshellarg(Config::get('composer')),
                        escapeshellarg(Config::get('projectPath'))
                    ));
                }
            }

            if (Config::get('classmap_file')) {
                $this->classMap = require(Config::get('classmap_file'));
            }
        }

        return $this->classMap;
    }

    /**
     * Format parameters for the autocomplete plugin
     * @param ReflectionMethod $method    Method to get arguments from
     * @param string           $className Class name to use (optional for the moment)
     * @return array
     */
    protected function getMethodArguments($method, $className = null)
    {
        $args = $method->getParameters();
        $optionals = array();
        $parameters = array();

        foreach ($args as $argument) {
            $value = '$' . $argument->getName();

            if ($argument->isPassedByReference()) {
                $value = '&' . $value;
            }

            if ($argument->isOptional()) {
                $optionals[] = $value;
            } else {
                $parameters[] = $value;
            }
        }

        if ($className) {
            $parser = new DocParser();
            $return = $parser->get($className, 'method', $method->getName(), array(DocParser::RETURN_VALUE));
            $descriptions = $parser->get($className, 'method', $method->getName(), array(DocParser::DESCRIPTION));
        }

        return array(
            'parameters' => $parameters,
            'optionals' => $optionals,
            'return'    => ($className && !empty($return)) ? $return['return'] : '',
            'descriptions' => ($className && $descriptions) ? $descriptions['descriptions'] : array()
        );
    }

    /**
     * Returns methods and properties of the given className
     * @param string $className Full namespace of the parsed class
     */
    protected function getClassMetadata($className)
    {
        $data = array(
            'class'  => $className,
            'names'  => array(),
            'values' => array()
        );

        try {
            $reflection = new ReflectionClass($className);
        } catch (Exception $e) {
            return $data;
        }

        $methods    = $reflection->getMethods();
        $attributes = $reflection->getProperties();
        $traits     = $reflection->getTraits();
        foreach ($traits as $trait) {
            $methods = array_merge($methods, $trait->getMethods());
        }

        // Methods
        foreach ($methods as $method) {
            $data['names'][] = $method->getName();

            $args = $this->getMethodArguments($method, $className);

            $data['values'][$method->getName()] = array(
                'isMethod'       => true,
                'isPublic'       => $method->isPublic(),
                'isProtected'    => $method->isProtected(),
                'args'           => $args,
                'declaringClass' => $method->getDeclaringClass()->name,
                'startLine'      => $method->getStartLine()
            );
        }

        // Properties
        foreach ($attributes as $attribute) {
            if (!in_array($attribute->getName(), $data['names'])) {
                $data['names'][] = $attribute->getName();
                $data['values'][$attribute->getName()] = null;
            }

            $parser = new DocParser();
            $return = $parser->get($className, 'property', $attribute->getName(), array(DocParser::VAR_TYPE));
            $descriptions = $parser->get($className, 'property', $attribute->getName(), array(DocParser::DESCRIPTION));

            $attributesValues = array(
{'fraction_non_alphanumeric': 0.1489139515455305, 'fraction_numerical': 0.0010442773600668337, 'mean_word_length': 1.7978381536663746, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 91, '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': '2605628', 'n_tokens_mistral': 2513, 'n_tokens_neox': 2421, 'n_words': 539}