<commit_before><?php declare(strict_types=1);
namespace Onion\Framework;

use Onion\Framework\Dependency\Container;
use Psr\Container\ContainerInterface;

function compileConfigFiles(string $configDir, string $env): array
{
    if (!is_dir($configDir)) {
        throw new \RuntimeException(
            "Configuration directory '{$configDir}' does not exist"
        );
    }

    /** @var \DirectoryIterator $directoryIterator */
    $directoryIterator = new \RecursiveIteratorIterator(
        new \RecursiveDirectoryIterator($configDir)
    );
    $configs = [];

    foreach ($directoryIterator as $file) {
        if ($directoryIterator->isDir() || $directoryIterator->isDot()) {
            continue;
        }
        $prefix = $file->getBasename(".global.php");
        if (!stripos($prefix, '.php') !== false) {
            $configs[$prefix] = include $file->getRealPath();
        }

        $prefix = $file->getBasename(".{$env}.php");
        if (!stripos($prefix, '.php') !== false) {
            if (!isset($configs)) {
                $configs[$prefix] = include $file->getRealPath();
            }

            $configs = merge($configs, [
                $prefix =>  include $file->getRealPath()
            ]);
        }
    }

    return $configs;
}

function merge(array $array1, array $array2): array
{
    foreach ($array2 as $key => $value) {
        if (array_key_exists($key, $array1)) {
            if (is_int($key)) {
                $array1[] = $value;
                continue;
            }

            if (is_array($value) && is_array($array1[$key])) {
                $array1[$key] = array_merge_distinct($array1[$key], $value);
                continue;
            }

            $array1[$key] = $value;
            continue;
        }
<commit_msg>Fix wrong function name in `merge` function<commit_after><?php declare(strict_types=1);
namespace Onion\Framework;

use Onion\Framework\Dependency\Container;
use Psr\Container\ContainerInterface;

function compileConfigFiles(string $configDir, string $env): array
{
    if (!is_dir($configDir)) {
        throw new \RuntimeException(
            "Configuration directory '{$configDir}' does not exist"
        );
    }

    /** @var \DirectoryIterator $directoryIterator */
    $directoryIterator = new \RecursiveIteratorIterator(
        new \RecursiveDirectoryIterator($configDir)
    );
    $configs = [];

    foreach ($directoryIterator as $file) {
        if ($directoryIterator->isDir() || $directoryIterator->isDot()) {
            continue;
        }
        $prefix = $file->getBasename(".global.php");
        if (!stripos($prefix, '.php') !== false) {
            $configs[$prefix] = include $file->getRealPath();
        }

        $prefix = $file->getBasename(".{$env}.php");
        if (!stripos($prefix, '.php') !== false) {
            if (!isset($configs)) {
                $configs[$prefix] = include $file->getRealPath();
            }

            $configs = merge($configs, [
                $prefix =>  include $file->getRealPath()
            ]);
        }
    }

    return $configs;
}

function merge(array $array1, array $array2): array
{
    foreach ($array2 as $key => $value) {
        if (array_key_exists($key, $array1)) {
            if (is_int($key)) {
                $array1[] = $value;
                continue;
            }

            if (is_array($value) && is_array($array1[$key])) {
                $array1[$key] = merge($array1[$key], $value);
                continue;
            }

            $array1[$key] = $value;
            continue;
        }

{'fraction_non_alphanumeric': 0.15294445994976277, 'fraction_numerical': 0.0055819145967066705, 'mean_word_length': 2.097666378565255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '5973443', 'n_tokens_mistral': 1028, 'n_tokens_neox': 1003, 'n_words': 202}