<commit_before><?php

declare(strict_types=1);

/*
 * This file is part of Analyzer.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace GrahamCampbell\Analyzer;

use AppendIterator;
use CallbackFilterIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

/**
 * This is the analysis trait.
 *
 * @author <NAME> <<EMAIL>>
 */
trait AnalysisTrait
{
    /**
     * Get the code paths to analyze.
     *
     * @return string[]
     */
    abstract protected function getPaths();

    /**
     * @dataProvider provideFilesToCheck
     */
    public function testReferences(string $file)
    {
        $this->assertTrue(file_exists($file), "Expected {$file} to exist.");

        foreach ((new ReferenceAnalyzer())->analyze($file) as $class) {
            $this->assertTrue(ClassInspector::inspect($class)->exists(), "Expected {$class} to exist.");
        }
    }

    public function provideFilesToCheck()
    {
        $iterator = new AppendIterator();

        foreach ($this->getPaths() as $path) {
            $iterator->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
        }

        $files = new CallbackFilterIterator($iterator, function ($file) {
            return $file->getFilename()[0] !== '.' && !$file->isDir();
        });

        return array_map(function ($file) {
            return [$file];
        }, iterator_to_array($files));
    }
}
<commit_msg>Added the ability to ignore classes not existing<commit_after><?php

declare(strict_types=1);

/*
 * This file is part of Analyzer.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace GrahamCampbell\Analyzer;

use AppendIterator;
use CallbackFilterIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

/**
 * This is the analysis trait.
 *
 * @author <NAME> <<EMAIL>>
 */
trait AnalysisTrait
{
    /**
     * Get the code paths to analyze.
     *
     * @return string[]
     */
    abstract protected function getPaths();

    /**
     * Get the classes to ignore not existing.
     *
     * @return string[]
     */
    protected function getIgnored()
    {
        return [];
    }

    /**
     * @dataProvider provideFilesToCheck
     */
    public function testReferences(string $file)
    {
        $this->assertTrue(file_exists($file), "Expected {$file} to exist.");

        $ignored = $this->getIgnored();

        foreach ((new ReferenceAnalyzer())->analyze($file) as $class) {
            if (in_array($class, $ignored, true)) {
                continue;
            }

            $this->assertTrue(ClassInspector::inspect($class)->exists(), "Expected {$class} to exist.");
        }
    }

    public function provideFilesToCheck()
    {
        $iterator = new AppendIterator();

        foreach ($this->getPaths() as $path) {
            $iterator->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
        }

        $files = new CallbackFilterIterator($iterator, function ($file) {
            return $file->getFilename()[0] !== '.' && !$file->isDir();
        });

        return array_map(function ($file) {
            return [$file];
        }, iterator_to_array($files));
    }
}

{'fraction_non_alphanumeric': 0.13603048959249486, 'fraction_numerical': 0.0011726766344180592, 'mean_word_length': 2.7167755991285403, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 32, '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': '4515086', 'n_tokens_mistral': 960, 'n_tokens_neox': 947, 'n_words': 247}