<commit_before><?php
namespace nochso\Omni\PhpCsFixer;

use Symfony\Component\Finder\Finder;

/**
 * DefaultFinder respects ignore files for Git, Mercurial and Darcs.
 */
class DefaultFinder extends Finder
{
    /**
     * @param array|string $dirs
     *
     * @return \nochso\Omni\PhpCsFixer\DefaultFinder
     */
    public static function createIn($dirs)
    {
        $finder = new self();
        $finder->in($dirs);
        return $finder;
    }

    public function __construct()
    {
        parent::__construct();

        $excludes = [];
        foreach ($this->getVcsIgnoreFiles() as $ignore) {
            $excludes = array_merge($excludes, $this->readExcludeLines($ignore));
        }
        foreach ($this->getNames() as $name) {
            $this->name($name);
        }
        $this->files()
            ->ignoreDotFiles(true)
            ->ignoreVCS(true)
            ->exclude($excludes)
        ;
    }

    /**
     * @return array
     */
    protected function getNames()
    {
        return [
            '*.php',
            '*.twig',
            '#.*.ya?ml#i',
            '*.xml',
        ];
    }

    /**
     * @return array
     */
    protected function getVcsIgnoreFiles()
    {
        return [
            '.gitignore',
            '.hgignore',
            '_darcs/prefs/boring',
        ];
    }

    /**
     * @param $ignoreFile
     *
     * @return array
     */
    private function readExcludeLines($ignoreFile)
    {
        if (!is_file($ignoreFile)) {
            return [];
        }
        $lines = file($ignoreFile);
        if ($lines === false) {
            // Not sure how to test, so ignore it instead of inlining it above
            return []; // @codeCoverageIgnore
        }
        return array_map(function ($line) {
            return rtrim($line, "\r\n\\/");
        }, $lines);
    }
}<commit_msg>refactor: Rearrange DefaultFinder<commit_after><?php
namespace nochso\Omni\PhpCsFixer;

use nochso\Omni\Path;
use Symfony\Component\Finder\Finder;

/**
 * DefaultFinder respects ignore files for Git, Mercurial and Darcs.
 */
class DefaultFinder extends Finder
{
    /**
     * @param array|string $dirs
     *
     * @return \nochso\Omni\PhpCsFixer\DefaultFinder
     */
    public static function createIn($dirs)
    {
        $finder = new self();
        if (!is_array($dirs)) {
            $dirs = [$dirs];
        }
        $finder->in($dirs);
        $excludes = [];
        foreach ($finder->getVcsIgnoreFiles($dirs) as $ignore) {
            $excludes = array_merge($excludes, $finder->readExcludeLines($ignore));
        }
        $finder->exclude($excludes);
        return $finder;
    }

    public function __construct()
    {
        parent::__construct();

        foreach ($this->getNames() as $name) {
            $this->name($name);
        }
        $this->files()
            ->ignoreDotFiles(true)
            ->ignoreVCS(true)
        ;
    }

    /**
     * @return array
     */
    protected function getNames()
    {
        return [
            '*.php',
            '*.twig',
            '#.*.ya?ml#i',
            '*.xml',
        ];
    }

    /**
     * @param array $dirs
     *
     * @return array
     */
    protected function getVcsIgnoreFiles(array $dirs)
    {
        $files = [
            '.gitignore',
            '.hgignore',
            '_darcs/prefs/boring',
        ];
        $filepaths = [];
        foreach ($dirs as $dir) {
            foreach ($files as $file) {
                $filepaths[] = Path::combine($dir, $file);
            }
        }
        return $filepaths;
    }

    /**
     * @param $ignoreFile
     *
     * @return array
     */
    private function readExcludeLines($ignoreFile)
    {
        if (!file_exists($ignoreFile)) {
            return [];
        }
        $lines = file($ignoreFile);
        if ($lines === false) {
            // Not sure how to test, so ignore it instead of inlining it above
            return []; // @codeCoverageIgnore
        }
        return array_map(function ($line) {
            return rtrim($line, "\r\n\\/");
        }, $lines);
    }
}
{'fraction_non_alphanumeric': 0.14410692588092344, 'fraction_numerical': 0.0, 'mean_word_length': 1.5757196495619525, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2114833', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1232, 'n_words': 246}