<commit_before><?php

namespace TomPHP\ConfigServiceProvider;

use ArrayAccess;
use IteratorAggregate;
use TomPHP\ConfigServiceProvider\Exception\EntryDoesNotExistException;
use TomPHP\ConfigServiceProvider\Exception\NoMatchingFilesException;
use TomPHP\ConfigServiceProvider\Exception\ReadOnlyException;
use TomPHP\ConfigServiceProvider\FileReader\FileLocator;
use TomPHP\ConfigServiceProvider\FileReader\ReaderFactory;

final class ApplicationConfig implements ArrayAccess, IteratorAggregate
{
    /**
     * @var array
     */
    private $config;

    /**
     * @var string
     */
    private $separator;

    /**
     * @api
     *
     * @param array  $patterns
     * @param string $separator
     *
     * @return ApplicationConfig
     */
    public static function fromFiles(array $patterns, $separator = '.')
    {
        $locator = new FileLocator();
        $files   = array_reduce(
            $patterns,
            function (array $result, $pattern) use ($locator) {
                return array_merge($result, $locator->locate($pattern));
            },
            []
        );

        if (empty($files)) {
            throw NoMatchingFilesException::fromPatterns($patterns);
        }

        $factory = new ReaderFactory([
            '.json' => 'TomPHP\ConfigServiceProvider\FileReader\JSONFileReader',
            '.php'  => 'TomPHP\ConfigServiceProvider\FileReader\PHPFileReader',
        ]);

        $configs = array_map(
            function ($filename) use ($factory) {
                $reader = $factory->create($filename);

                return $reader->read($filename);
            },
            $files
        );

        $config = call_user_func_array('array_replace_recursive', $configs);

        return new self($config, $separator);
    }

    /**
     * @api
     *
     * @param array  $config
     * @param string $separator
     */
    public function __construct(array $config, $separator = '.')
    {
        $this->config    = $config;
        $this->separator = $separator;
    }

    public function getIterator()<commit_msg>Remove out of date @api annotations<commit_after><?php

namespace TomPHP\ConfigServiceProvider;

use ArrayAccess;
use IteratorAggregate;
use TomPHP\ConfigServiceProvider\Exception\EntryDoesNotExistException;
use TomPHP\ConfigServiceProvider\Exception\NoMatchingFilesException;
use TomPHP\ConfigServiceProvider\Exception\ReadOnlyException;
use TomPHP\ConfigServiceProvider\FileReader\FileLocator;
use TomPHP\ConfigServiceProvider\FileReader\ReaderFactory;

final class ApplicationConfig implements ArrayAccess, IteratorAggregate
{
    /**
     * @var array
     */
    private $config;

    /**
     * @var string
     */
    private $separator;

    /**
     * @param array  $patterns
     * @param string $separator
     *
     * @return ApplicationConfig
     */
    public static function fromFiles(array $patterns, $separator = '.')
    {
        $locator = new FileLocator();
        $files   = array_reduce(
            $patterns,
            function (array $result, $pattern) use ($locator) {
                return array_merge($result, $locator->locate($pattern));
            },
            []
        );

        if (empty($files)) {
            throw NoMatchingFilesException::fromPatterns($patterns);
        }

        $factory = new ReaderFactory([
            '.json' => 'TomPHP\ConfigServiceProvider\FileReader\JSONFileReader',
            '.php'  => 'TomPHP\ConfigServiceProvider\FileReader\PHPFileReader',
        ]);

        $configs = array_map(
            function ($filename) use ($factory) {
                $reader = $factory->create($filename);

                return $reader->read($filename);
            },
            $files
        );

        $config = call_user_func_array('array_replace_recursive', $configs);

        return new self($config, $separator);
    }

    /**
     * @param array  $config
     * @param string $separator
     */
    public function __construct(array $config, $separator = '.')
    {
        $this->config    = $config;
        $this->separator = $separator;
    }

    public function getIterator()
{'fraction_non_alphanumeric': 0.11467889908256881, 'fraction_numerical': 0.0, 'mean_word_length': 2.390343698854337, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '2234673', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1108, 'n_words': 220}