<commit_before><?php

namespace PhpDA\Parser\Visitor\Required;

use PhpDA\Parser\Visitor\AbstractVisitor;
use PhpDA\Plugin\ConfigurableInterface;
use PhpParser\Node;

class UsedNamespaceCollector extends AbstractVisitor implements ConfigurableInterface
{
    /** @var int|null */
    private $offset;

    /** @var int|null */
    private $length;

    /** @var array */
    private $ignoredNamespaces = array('self', 'static');

    public function setOptions(array $options)
    {
        if (isset($options['offset'])) {
            $this->offset = (int) $options['offset'];
        }

        if (isset($options['length'])) {
            $this->length = (int) $options['length'];
        }
    }

    public function leaveNode(Node $node)
    {
        if ($node instanceof Node\Name) {
            if (!$this->ignores($node)) {
                $node = $this->filter($node);
                $this->getAnalysis()->addUsedNamespace($node);
            }
        }
    }

    /**
     * @param Node\Name $name
     * @return Node\Name
     */
    private function filter(Node\Name $name)
    {
        if (is_null($this->offset) && is_null($this->length)) {
            return $name;
        }

        if (is_null($this->length)) {
            $parts = array_slice($name->parts, (int) $this->offset);
        } else {
            $parts = array_slice($name->parts, (int) $this->offset, (int) $this->length);
        }

        return new Node\Name($parts);
    }

    /**
     * @param Node\Name $name
     * @return bool
     */
    private function ignores(Node\Name $name)
    {
        return in_array($name->toString(), $this->ignoredNamespaces);
    }
}<commit_msg>add configurable feature to plugin loader and visitors<commit_after><?php

namespace PhpDA\Parser\Visitor\Required;

use PhpDA\Parser\Visitor\AbstractVisitor;
use PhpDA\Plugin\ConfigurableInterface;
use PhpParser\Node;

class UsedNamespaceCollector extends AbstractVisitor implements ConfigurableInterface
{
    /** @var int|null */
    private $offset;

    /** @var int|null */
    private $length;

    /** @var int */
    private $minLength = 0;

    /** @var array */
    private $ignoredNamespaces = array('self', 'static');

    public function setOptions(array $options)
    {
        if (isset($options['offset'])) {
            $this->offset = (int) $options['offset'];
        }

        if (isset($options['length'])) {
            $this->length = (int) $options['length'];
        }

        if (isset($options['minLength'])) {
            $this->minLength = (int) $options['minLength'];
        }
    }

    public function leaveNode(Node $node)
    {
        if ($node instanceof Node\Name) {
            if (!$this->ignores($node)) {
                $node = $this->filter($node);
                $this->getAnalysis()->addUsedNamespace($node);
            }
        }
    }

    /**
     * @param Node\Name $name
     * @return bool
     */
    private function ignores(Node\Name $name)
    {
        if ($this->minLength > 0) {
            return count($name->parts) < $this->minLength;
        }

        return in_array($name->toString(), $this->ignoredNamespaces);
    }

    /**
     * @param Node\Name $name
     * @return Node\Name
     */
    private function filter(Node\Name $name)
    {
        if (is_null($this->offset) && is_null($this->length)) {
            return $name;
        }

        if (is_null($this->length)) {
            $parts = array_slice($name->parts, (int) $this->offset);
        } else {
            $parts = array_slice($name->parts, (int) $this->offset, (int) $this->length);
        }

        return new Node\Name($parts);
    }
}
{'fraction_non_alphanumeric': 0.15695925622094614, 'fraction_numerical': 0.0005468963631391851, 'mean_word_length': 2.156169111302847, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 40, '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': '2271226', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1064, 'n_words': 219}