<commit_before><?php

namespace NodePub\Core\Trait;

use Symfony\Component\Finder\Finder;

trait SourceDirectoryAwareTrait {
    
    /**
     * @var array
     */
    protected $sourceDirs = array();
    
    /**
     * Adds a directory to the array of sources that will
     * be searched for themes to load.
     */
    public function addSource($sourcePath, $useStrict=true)
    {
        if (is_link($sourcePath)) {
            return $this->addSource(realpath($sourcePath), $useStrict);
        }
        
        if (is_dir($sourcePath)) {
            $this->sourceDirs[] = $sourcePath;
        } else {
            if (true === $useStrict) {
                throw new \Exception(sprintf('Path {%s} is not a readable directory', $sourcePath));
            }
        }
        
        return $this;
    }
    
    /**
     * Searches source directories for criteria in given Finder
     *
     * @return Finder
     */
    protected function findInSourceDirs(Finder $finder)
    {
        foreach ($this->sourceDirs as $dir) {
            $finder->in($dir);
        }

        return $finder;
    }
}<commit_msg>simplifying logic<commit_after><?php

namespace NodePub\Core\Trait;

use Symfony\Component\Finder\Finder;

trait SourceDirectoryAwareTrait {
    
    /**
     * @var array
     */
    protected $sourceDirs = array();
    
    /**
     * Adds a directory to the array of sources that will
     * be searched for themes to load.
     */
    public function addSource($sourcePath, $useStrict=true)
    {
        if (is_link($sourcePath)) {
            return $this->addSource(realpath($sourcePath), $useStrict);
        }
        
        if (is_dir($sourcePath)) {
            $this->sourceDirs[] = $sourcePath;
        } elseif (true === $useStrict) {
            throw new \Exception(sprintf('Path {%s} is not a readable directory', $sourcePath));
        }
        
        return $this;
    }
    
    /**
     * Searches source directories for criteria in given Finder
     *
     * @return Finder
     */
    protected function findInSourceDirs(Finder $finder)
    {
        foreach ($this->sourceDirs as $dir) {
            $finder->in($dir);
        }

        return $finder;
    }
}
{'fraction_non_alphanumeric': 0.11770031688546853, 'fraction_numerical': 0.0, 'mean_word_length': 1.9040735873850196, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '6075979', 'n_tokens_mistral': 654, 'n_tokens_neox': 653, 'n_words': 156}