<commit_before><?php
/**
 * phpDocumentor
 *
 * PHP Version 5.3
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2010-2012 <NAME> / Naenius (http://www.naenius.com)
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
 * @link      http://phpdoc.org
 */

namespace phpDocumentor\Reflection;

/**
 * Reflection class for a full file.
 *
 * @author   <NAME> <<EMAIL>>
 * @license  http://www.opensource.org/licenses/mit-license.php MIT
 * @link     http://phpdoc.org
 */
class FileReflector extends \PHPParser_NodeVisitorAbstract
{
    protected $hash = array('a' => 1, 'b' => 2);
    protected $contents = 1;
    protected $includes = array();
    protected $constants = array();
    protected $classes = array();
    protected $traits = array();
    protected $interfaces = array();
    protected $functions = array();
    protected $filename = '';
    protected $doc_block;
    protected $default_package_name = 'Default';

    /** @var string[] A list of markers contained in this file. */
    protected $markers = array();

    /** @var string[] A list of errors during processing */
    protected $parse_markers = array();

    /** @var string[] A list of all marker types to search for in this file. */
    protected $marker_terms = array('TODO', 'FIXME');

    protected $namespace_aliases = array();
    protected $current_namespace = '';

    /**
     * Opens the file and retrieves its contents.
     *
     * During construction the given file is checked whether it is readable and
     * if the $validate argument is true a PHP Lint action is executed to
     * check whether the there are no parse errors.
     *
     * By default the Lint check is disable because of the performance hit
     * introduced by this action.
     *
     * If the validation checks out the file's contents are read; converted to
     * UTF-8 and the has is created from those contents.
     *
     * @param string  $file     Name of the file.
     * @param boolean $validate Whether to check the file using PHP Lint.
     *
     * @throws \phpDocumentor\Reflection\Exception when the filename is incorrect or
     *   the file can not be opened
     */
    public function __construct($file, $validate = false)
    {
        if (!is_string($file) || (!is_readable($file))) {
            throw new \phpDocumentor\Reflection\Exception(
                'The given file should be a string, should exist on the '
                . 'filesystem and should be readable'
            );
        }

        if ($validate) {
            exec('php -l ' . escapeshellarg($file), $output, $result);
            if ($result != 0) {
                throw new \phpDocumentor\Reflection\Exception(
                    'The given file could not be interpreted as it contains '
                    . 'errors: ' . implode(PHP_EOL, $output)
                );
            }
        }

        $this->filename = $file;
        $this->contents = file_get_contents($file);

        // filemtime($file) is sometimes between 0.00001 and 0.00005 seconds
        // faster but md5 is more accurate
        // real world tests with larger code bases should determine how much
        // it really matters
        $this->hash = md5($this->contents);
    }

    public function process()
    {
        $traverser = new Traverser();
        $traverser->visitor = $this;
        $traverser->traverse($this->contents);

        $this->scanForMarkers();
    }

    public function getClasses()
    {
        return $this->classes;
    }

    public function getTraits()
    {
        return $this->traits;
    }

    public function getConstants()
    {
        return $this->constants;
    }

    public function getFunctions()
    {
        return $this->functions;
    }

    public function getIncludes()
    {
        return $this->includes;
    }

    public function getInterfaces()
    {
        return $this->interfaces;
    }

    public function enterNode(\PHPParser_Node $node)
    {
        $prettyPrinter = new \PHPParser_PrettyPrinter_Zend;

        switch(get_class($node)) {
            case 'PHPParser_Node_Stmt_Use':
                /** @var \PHPParser_Node_Stmt_UseUse $use */
                foreach ($node->uses as $use) {
                    $this->namespace_aliases[$use->alias]
                        = implode('\\', $use->name->parts);
                }
                break;
            case 'PHPParser_Node_Stmt_Namespace':
                $this->current_namespace = implode('\\', $node->name->parts);
                break;
            case 'PHPParser_Node_Stmt_Class':
                $this->classes[] = new ClassReflector($node);
                break;
            case 'PHPParser_Node_Stmt_Trait':
                $this->traits[] = new TraitReflector($node);
                break;
            case 'PHPParser_Node_Stmt_Interface':
                $this->interfaces[] = new InterfaceReflector($node);
                break;
            case 'PHPParser_Node_Stmt_Function':
                $this->functions[] = new FunctionReflector($node);
                break;
            case 'PHPParser_Node_Stmt_Const':
                foreach ($node->consts as $constant) {
                    $reflector = new ConstantReflector($constant);
                    $this->constants[$reflector->getName()] = $reflector;
                }
                break;
            case 'PHPParser_Node_Expr_FuncCall':
                if ($node->name instanceof \PHPParser_Node_Name
                    && $node->name == 'define'
                ) {
                    $constant = new \PHPParser_Node_Const(
                        $prettyPrinter->prettyPrintExpr($node->args[0]->value),
                        $node->args[1]->value,
                        $node->getAttributes()
                    );
                    $constant->namespacedName = new \PHPParser_Node_Name(
                        $this->current_namespace.'\\'.$constant->name
                    );

                    $reflector = new ConstantReflector($constant);
                    $this->constants[$reflector->getName()] = $reflector;
                }
                break;
            case 'PHPParser_Node_Expr_Include':
                $this->includes[] = new IncludeReflector($node);
                break;
        }
    }

    public function getFilename()
    {
        return $this->filename;
    }

    public function getHash()
    {
        return $this->hash;
    }

    public function getDocBlock()
    {
        return $this->doc_block;
    }

    public function getDefaultPackageName()
    {
        return $this->default_package_name;<commit_msg>Define statement incorrectly show the constant definition and namespace<commit_after><?php
/**
 * phpDocumentor
 *
 * PHP Version 5.3
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2010-2012 <NAME> / Naenius (http://www.naenius.com)
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
 * @link      http://phpdoc.org
 */

namespace phpDocumentor\Reflection;

/**
 * Reflection class for a full file.
 *
 * @author   <NAME> <<EMAIL>>
 * @license  http://www.opensource.org/licenses/mit-license.php MIT
 * @link     http://phpdoc.org
 */
class FileReflector extends \PHPParser_NodeVisitorAbstract
{
    protected $hash = array('a' => 1, 'b' => 2);
    protected $contents = 1;
    protected $includes = array();
    protected $constants = array();
    protected $classes = array();
    protected $traits = array();
    protected $interfaces = array();
    protected $functions = array();
    protected $filename = '';
    protected $doc_block;
    protected $default_package_name = 'Default';

    /** @var string[] A list of markers contained in this file. */
    protected $markers = array();

    /** @var string[] A list of errors during processing */
    protected $parse_markers = array();

    /** @var string[] A list of all marker types to search for in this file. */
    protected $marker_terms = array('TODO', 'FIXME');

    protected $namespace_aliases = array();
    protected $current_namespace = '';

    /**
     * Opens the file and retrieves its contents.
     *
     * During construction the given file is checked whether it is readable and
     * if the $validate argument is true a PHP Lint action is executed to
     * check whether the there are no parse errors.
     *
     * By default the Lint check is disable because of the performance hit
     * introduced by this action.
     *
     * If the validation checks out the file's contents are read; converted to
     * UTF-8 and the has is created from those contents.
     *
     * @param string  $file     Name of the file.
     * @param boolean $validate Whether to check the file using PHP Lint.
     *
     * @throws \phpDocumentor\Reflection\Exception when the filename is incorrect or
     *   the file can not be opened
     */
    public function __construct($file, $validate = false)
    {
        if (!is_string($file) || (!is_readable($file))) {
            throw new \phpDocumentor\Reflection\Exception(
                'The given file should be a string, should exist on the '
                . 'filesystem and should be readable'
            );
        }

        if ($validate) {
            exec('php -l ' . escapeshellarg($file), $output, $result);
            if ($result != 0) {
                throw new \phpDocumentor\Reflection\Exception(
                    'The given file could not be interpreted as it contains '
                    . 'errors: ' . implode(PHP_EOL, $output)
                );
            }
        }

        $this->filename = $file;
        $this->contents = file_get_contents($file);

        // filemtime($file) is sometimes between 0.00001 and 0.00005 seconds
        // faster but md5 is more accurate
        // real world tests with larger code bases should determine how much
        // it really matters
        $this->hash = md5($this->contents);
    }

    public function process()
    {
        $traverser = new Traverser();
        $traverser->visitor = $this;
        $traverser->traverse($this->contents);

        $this->scanForMarkers();
    }

    public function getClasses()
    {
        return $this->classes;
    }

    public function getTraits()
    {
        return $this->traits;
    }

    public function getConstants()
    {
        return $this->constants;
    }

    public function getFunctions()
    {
        return $this->functions;
    }

    public function getIncludes()
    {
        return $this->includes;
    }

    public function getInterfaces()
    {
        return $this->interfaces;
    }

    public function enterNode(\PHPParser_Node $node)
    {
        $prettyPrinter = new \PHPParser_PrettyPrinter_Zend;

        switch(get_class($node)) {
            case 'PHPParser_Node_Stmt_Use':
                /** @var \PHPParser_Node_Stmt_UseUse $use */
                foreach ($node->uses as $use) {
                    $this->namespace_aliases[$use->alias]
                        = implode('\\', $use->name->parts);
                }
                break;
            case 'PHPParser_Node_Stmt_Namespace':
                $this->current_namespace = implode('\\', $node->name->parts);
                break;
            case 'PHPParser_Node_Stmt_Class':
                $this->classes[] = new ClassReflector($node);
                break;
            case 'PHPParser_Node_Stmt_Trait':
                $this->traits[] = new TraitReflector($node);
                break;
            case 'PHPParser_Node_Stmt_Interface':
                $this->interfaces[] = new InterfaceReflector($node);
                break;
            case 'PHPParser_Node_Stmt_Function':
                $this->functions[] = new FunctionReflector($node);
                break;
            case 'PHPParser_Node_Stmt_Const':
                foreach ($node->consts as $constant) {
                    $reflector = new ConstantReflector($constant);
                    $this->constants[$reflector->getName()] = $reflector;
                }
                break;
            case 'PHPParser_Node_Expr_FuncCall':
                if ($node->name instanceof \PHPParser_Node_Name
                    && $node->name == 'define'
                ) {
                    $name = trim(
                        $prettyPrinter->prettyPrintExpr($node->args[0]->value),
                        '\''
                    );
                    $constant = new \PHPParser_Node_Const(
                        $name,
                        $node->args[1]->value,
                        $node->getAttributes()
                    );
                    $constant->namespacedName = new \PHPParser_Node_Name(
                        ($this->current_namespace
                            ? $this->current_namespace.'\\' : '')
                        .$name
                    );

                    $reflector = new ConstantReflector($constant);
                    $this->constants[$reflector->getName()] = $reflector;
                }
                break;
            case 'PHPParser_Node_Expr_Include':
                $this->includes[] = new IncludeReflector($node);
                break;
        }
    }

    public function getFilename()
    {
        return $this->filename;
    }

    public function getHash()
    {
        return $this->hash;
    }

    public function getDocBlock()
    {
        return $this->doc_block;
    }

    public function getDefaultPackageName()
    {
        return $this->default_package_name;
{'fraction_non_alphanumeric': 0.11142391465402282, 'fraction_numerical': 0.004593273077492962, 'mean_word_length': 1.8093652445369406, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '5928327', 'n_tokens_mistral': 3687, 'n_tokens_neox': 3539, 'n_words': 948}