<commit_before><?php
/******************************************************************************
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
 *
 * Copyright (c) 2016, 2015 <NAME> <<EMAIL>>
 *
 * This software is licensed under The MIT License. You should have received
 * a copy of the licence along with the code.
 */

namespace Lechimp\Dicto\Indexer\PhpParser;

use Lechimp\Dicto\Analysis\Consts;
use Lechimp\Dicto\Indexer as I;
use PhpParser\Node as N;

/**
 * Detects dependencies.
 */
class DependenciesListener extends Listener {
    /**
     * @var int[]|null
     */
    protected $dependent_entity_ids = array();


    public function on_enter_class($id, N\Stmt\Class_ $class) {
        assert('is_int($id)');
        // Every interesting reference we find will create a dependency
        // on this class.
        $this->dependent_entity_ids[] = $id;
    }

    public function on_leave_class($id) {
        assert('is_int($id)');
        // Done with the dependencies of this class.
        $this->remove_from($id, $this->dependent_entity_ids);
    }

    public function on_enter_method($id, N\Stmt\ClassMethod $method) {
        assert('is_int($id)');
        // Every interesting reference we find will create a dependency
        // on this method.
        $this->dependent_entity_ids[] = $id;
    }

    public function on_leave_method($id) {
        assert('is_int($id)');
        // Done with the dependencies of this method.
        $this->remove_from($id, $this->dependent_entity_ids);
    }

    public function on_enter_function($id, N\Stmt\Function_ $function) {
        assert('is_int($id)');
        // Every interesting reference we find will create a dependency
        // on this function.
        $this->dependent_entity_ids[] = $id;
    }

    public function on_leave_function($id) {
        assert('is_int($id)');
        // Done with the dependencies of this function.
        $this->remove_from($id, $this->dependent_entity_ids);
    }

    public function on_enter_misc(\PhpParser\Node $node) {
        $ref_ids = array();
        if ($node instanceof N\Expr\MethodCall) {
            $ref_ids[] = $this->indexer->get_reference
                ( Consts::METHOD_ENTITY
                , $node->name
                , $node->getAttribute("startLine")
                );
        }
        elseif($node instanceof N\Expr\FuncCall) {
            $ref_ids[] = $this->indexer->get_reference
                ( Consts::FUNCTION_ENTITY
                , $node->name->parts[0]
                , $node->getAttribute("startLine")
                );
        }
        elseif ($node instanceof N\Stmt\Global_) {
            foreach ($node->vars as $var) {
                assert('$var instanceof \\PhpParser\\Node\\Expr\\Variable');
                assert('is_string($var->name)');
                $ref_ids[] = $this->indexer->get_reference
                    ( Consts::GLOBAL_ENTITY
                    , $var->name
                    , $node->getAttribute("startLine")
                    );
            }
        }
        elseif ($node instanceof N\Expr\ArrayDimFetch) {
            if ($node->var->name == "GLOBALS") {
                $ref_ids[] = $this->indexer->get_reference
                    ( Consts::GLOBAL_ENTITY
                    , $node->dim->value
                    , $node->getAttribute("startLine")
                    );
            }
        }
        foreach ($ref_ids as $ref_id) {
            $start_line = $node->getAttribute("startLine");
            $source_line = $this->lines_from_to($start_line, $start_line);
            // Record a dependency for every entity we currently know as dependent.
            foreach ($this->dependent_entity_ids as $dependent_id) {
                $this->insert->dependency
                    ( $dependent_id
                    , $ref_id<commit_msg>passes tests on stfu operator<commit_after><?php
/******************************************************************************
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
 *
 * Copyright (c) 2016, 2015 <NAME> <<EMAIL>>
 *
 * This software is licensed under The MIT License. You should have received
 * a copy of the licence along with the code.
 */

namespace Lechimp\Dicto\Indexer\PhpParser;

use Lechimp\Dicto\Analysis\Consts;
use Lechimp\Dicto\Indexer as I;
use PhpParser\Node as N;

/**
 * Detects dependencies.
 */
class DependenciesListener extends Listener {
    /**
     * @var int[]|null
     */
    protected $dependent_entity_ids = array();


    public function on_enter_class($id, N\Stmt\Class_ $class) {
        assert('is_int($id)');
        // Every interesting reference we find will create a dependency
        // on this class.
        $this->dependent_entity_ids[] = $id;
    }

    public function on_leave_class($id) {
        assert('is_int($id)');
        // Done with the dependencies of this class.
        $this->remove_from($id, $this->dependent_entity_ids);
    }

    public function on_enter_method($id, N\Stmt\ClassMethod $method) {
        assert('is_int($id)');
        // Every interesting reference we find will create a dependency
        // on this method.
        $this->dependent_entity_ids[] = $id;
    }

    public function on_leave_method($id) {
        assert('is_int($id)');
        // Done with the dependencies of this method.
        $this->remove_from($id, $this->dependent_entity_ids);
    }

    public function on_enter_function($id, N\Stmt\Function_ $function) {
        assert('is_int($id)');
        // Every interesting reference we find will create a dependency
        // on this function.
        $this->dependent_entity_ids[] = $id;
    }

    public function on_leave_function($id) {
        assert('is_int($id)');
        // Done with the dependencies of this function.
        $this->remove_from($id, $this->dependent_entity_ids);
    }

    public function on_enter_misc(\PhpParser\Node $node) {
        $ref_ids = array();
        if ($node instanceof N\Expr\MethodCall) {
            $ref_ids[] = $this->indexer->get_reference
                ( Consts::METHOD_ENTITY
                , $node->name
                , $node->getAttribute("startLine")
                );
        }
        elseif($node instanceof N\Expr\FuncCall) {
            $ref_ids[] = $this->indexer->get_reference
                ( Consts::FUNCTION_ENTITY
                , $node->name->parts[0]
                , $node->getAttribute("startLine")
                );
        }
        elseif ($node instanceof N\Stmt\Global_) {
            foreach ($node->vars as $var) {
                assert('$var instanceof \\PhpParser\\Node\\Expr\\Variable');
                assert('is_string($var->name)');
                $ref_ids[] = $this->indexer->get_reference
                    ( Consts::GLOBAL_ENTITY
                    , $var->name
                    , $node->getAttribute("startLine")
                    );
            }
        }
        elseif ($node instanceof N\Expr\ArrayDimFetch) {
            if ($node->var->name == "GLOBALS") {
                $ref_ids[] = $this->indexer->get_reference
                    ( Consts::GLOBAL_ENTITY
                    , $node->dim->value
                    , $node->getAttribute("startLine")
                    );
            }
        }
        elseif ($node instanceof N\Expr\ErrorSuppress) {
            $ref_ids[] = $this->indexer->get_reference
                    ( Consts::LANGUAGE_CONSTRUCT_ENTITY
                    , "@"
                    , $node->getAttribute("startLine")
                    );
        }
        foreach ($ref_ids as $ref_id) {
            $start_line = $node->getAttribute("startLine");
            $source_line = $this->lines_from_to($start_line, $start_line);
            // Record a dependency for every entity we currently know as dependent.
            foreach ($this->dependent_entity_ids as $dependent_id) {
                $this->insert->dependency
                    ( $dependent_id
                    , $ref_id
{'fraction_non_alphanumeric': 0.1423412204234122, 'fraction_numerical': 0.00224159402241594, 'mean_word_length': 1.9504041146216018, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 84, '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': '362593', 'n_tokens_mistral': 2267, 'n_tokens_neox': 2190, 'n_words': 487}