<commit_before><?php namespace TightenCo\Jigsaw;

class DataLoader
{
    private $basePath;
    private $collectionDataLoader;

    public function __construct($basePath, $collectionDataLoader)
    {
        $this->basePath = $basePath;
        $this->collectionDataLoader = $collectionDataLoader;
    }

    public function load($source, $env)
    {
        return [
            'site' => array_merge($this->loadConfigData($env), $this->loadCollectionData($source)),
        ];
    }

    private function loadConfigData($env)
    {
        if (file_exists($this->basePath . "/config.{$env}.php")) {
            $environmentConfig = include $this->basePath . "/config.{$env}.php";
        } else {
            $environmentConfig = [];
        }

        return array_merge(include $this->basePath . '/config.php', $environmentConfig);
    }

    private function loadCollectionData($source)
    {
        return $this->collectionDataLoader->load($source);
    }
}
<commit_msg>Convert arrays in site data collection to IterableObjects<commit_after><?php namespace TightenCo\Jigsaw;

class DataLoader
{
    private $basePath;
    private $collectionDataLoader;

    public function __construct($basePath, $collectionDataLoader)
    {
        $this->basePath = $basePath;
        $this->collectionDataLoader = $collectionDataLoader;
    }

    public function load($source, $env)
    {
        return $this->makeIterableObject(
            array_merge($this->loadConfigData($env), $this->loadCollectionData($source))
        );
    }

    private function loadConfigData($env)
    {
        if (file_exists($this->basePath . "/config.{$env}.php")) {
            $environmentConfig = include $this->basePath . "/config.{$env}.php";
        } else {
            $environmentConfig = [];
        }

        return array_merge(include $this->basePath . '/config.php', $environmentConfig);

    private function makeIterableObject($array)
    {
        return collect($array)->map(function ($item, $_) {
            return is_array($item) ? new IterableObject($this->makeIterableObject($item)) : $item;
        });
    }

    private function loadCollectionData($source)
    {
        return $this->collectionDataLoader->load($source);
    }
}

{'fraction_non_alphanumeric': 0.13410818059901655, 'fraction_numerical': 0.0, 'mean_word_length': 2.799660441426146, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '5130352', 'n_tokens_mistral': 623, 'n_tokens_neox': 613, 'n_words': 112}