<commit_before><commit_msg>Added SimpleTraverser<commit_after><?php
declare(strict_types=1);
namespace Morpho\Code;

use PhpParser\Node;

class SimpleTraverser {
    public function traverseArray(array $nodes, \Closure $fn) {
        foreach ($nodes as $node) {
            if ($node instanceof Node) {
                $fn($node);
                $this->traverseNode($node, $fn);
            }
        }
    }

    private function traverseNode(Node $node, \Closure $fn) {
        foreach ($node->getSubNodeNames() as $name) {
            $subNode =& $node->$name;
            if (\is_array($subNode)) {
                $this->traverseArray($subNode, $fn);
            } elseif ($subNode instanceof Node) {
                $this->traverseNode($subNode, $fn);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.13670886075949368, 'fraction_numerical': 0.0012658227848101266, 'mean_word_length': 2.019083969465649, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, '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': '1754882', 'n_tokens_mistral': 243, 'n_tokens_neox': 232, 'n_words': 48}