<commit_before><?php

namespace KnpU\ActivityRunner\PhpParser\Visitor;

/**
 * The class Filter visitor returns all class decarations found in the code. If
 * the optional `$className` argument is passed, the visitor looks for the class
 * declaration that matches this specific name.
 *
 * @author <NAME> <<EMAIL>>
 */
class ClassFilterVisitor extends \PHPParser_NodeVisitorAbstract
{
    /**
     * @var string
     */
    protected $className;

    /**
     * @param string|null $className
     */
    public function __construct($className = null)
    {
        $this->className = $className;
    }

    /**
     * {@inheritDoc}
     */
    public function leaveNode(\PHPParser_Node $node)
    {
        if ($node instanceof \PHPParser_Node_Stmt_Class) {

            // Keep classes.
            return null;

        } elseif (is_array($node->stmts)) {
            // Iterates over children and finds all classes, then returns them
            // all. This way the classes bubble up to the top of the tree.
            $classes = array();

            foreach ($node->stmts as $stmt) {
                if ($stmt instanceof \PHPParser_Node_Stmt_Class) {
                    $classes[] = $stmt;
                }
            }

            if (count($classes) > 0) {
                return $classes;
            }
        }

        // Remove the node as there were no immediate child nodes as classes.
        return false;
    }

    /**
     * {@inheritDoc}
     */
    public function afterTraverse(array $nodes)
    {
        if (!$this->className) {
            return;
        }<commit_msg>Fixing ClassFilterVisitor too eager removing nodes<commit_after><?php

namespace KnpU\ActivityRunner\PhpParser\Visitor;

/**
 * The class Filter visitor returns all class decarations found in the code. If
 * the optional `$className` argument is passed, the visitor looks for the class
 * declaration that matches this specific name.
 *
 * @author <NAME> <<EMAIL>>
 */
class ClassFilterVisitor extends \PHPParser_NodeVisitorAbstract
{
    /**
     * @var string
     */
    protected $className;

    /**
     * @param string|null $className
     */
    public function __construct($className = null)
    {
        $this->className = $className;
    }

    /**
     * {@inheritDoc}
     */
    public function leaveNode(\PHPParser_Node $node)
    {
        if (is_array($node->stmts)) {
            // Iterates over children and finds all classes, then returns them
            // all. This way the classes bubble up to the top of the tree.
            $classes = array();

            foreach ($node->stmts as $stmt) {
                if ($stmt instanceof \PHPParser_Node_Stmt_Class) {
                    $classes[] = $stmt;
                }
            }

            if (count($classes) > 0) {
                return $classes;
            }
        }
    }

    /**
     * {@inheritDoc}
     */
    public function afterTraverse(array $nodes)
    {
        if (!$this->className) {
            return;
        }
{'fraction_non_alphanumeric': 0.10540271793172025, 'fraction_numerical': 0.0006629101756711965, 'mean_word_length': 1.836466165413534, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '4263768', 'n_tokens_mistral': 814, 'n_tokens_neox': 804, 'n_words': 245}