<commit_before><?php

namespace Exen\Konfig;

use Exen\Konfig\Exception\EmptyDirectoryException;
use Exen\Konfig\Exception\FileNotFoundException;
use Exen\Konfig\Exception\UnsupportedFormatException;

class Konfig extends AbstractKonfig
{
    /**
     * All file formats supported by Konfig
     *
     * @var array
     */
    private $_supportedFileParsers = [
        'Exen\Konfig\KonfigFileParser\Ini',
        'Exen\Konfig\KonfigFileParser\Json',
        'Exen\Konfig\KonfigFileParser\Php',
        'Exen\Konfig\KonfigFileParser\Toml',
        'Exen\Konfig\KonfigFileParser\Xml',
        'Exen\Konfig\KonfigFileParser\Yaml',
    ];

    /**
     * Loads a supported configuration file format.
     *
     * @param  string | array $path
     * @throws EmptyDirectoryException If `$path` is an empty directory
     */
    public function __construct($path = null)
    {
        $paths = $this->getValidPath($path);

        $this->data = [];

        foreach ($paths as $path) {
            // Get file information
            $ext = pathinfo($path, PATHINFO_EXTENSION);
            $parser = $this->getParser($ext);

            // Try and load file
            $this->data = array_replace_recursive($this->data, $parser->parse($path));
        } // END foreach

        parent::__construct($this->data);
    }

    /**
     * Static method for loading a Konfig instance.
     *
     * @param  string | array $path
     * @return Konfig
     */
    public static function load($path = null)
    {
        return new static($path);
    }

    /**
     * Gets a parser for a given file extension
     *
     * @param  string $ext
     * @return Konfig\KonfigFileParser\IKonfigFileParser
     * @throws UnsupportedFormatException If `$path` is an unsupported file format
     */
    private function getParser($ext = null)
    {
        $parser = null;

        foreach ($this->_supportedFileParsers as $fileParser) {
            // require_once 'FileParser/' . $fileParser . '.php';

            $tempParser = new $fileParser;

            if (in_array($ext, $tempParser->getSupportedFileExtensions($ext), true)) {
                $parser = $tempParser;
                continue;<commit_msg>The first matched parser is enough, right?<commit_after><?php

namespace Exen\Konfig;

use Exen\Konfig\Exception\EmptyDirectoryException;
use Exen\Konfig\Exception\FileNotFoundException;
use Exen\Konfig\Exception\UnsupportedFormatException;

class Konfig extends AbstractKonfig
{
    /**
     * All file formats supported by Konfig
     *
     * @var array
     */
    private $_supportedFileParsers = [
        'Exen\Konfig\KonfigFileParser\Ini',
        'Exen\Konfig\KonfigFileParser\Json',
        'Exen\Konfig\KonfigFileParser\Php',
        'Exen\Konfig\KonfigFileParser\Toml',
        'Exen\Konfig\KonfigFileParser\Xml',
        'Exen\Konfig\KonfigFileParser\Yaml',
    ];

    /**
     * Loads a supported configuration file format.
     *
     * @param  string | array $path
     * @throws EmptyDirectoryException If `$path` is an empty directory
     */
    public function __construct($path = null)
    {
        $paths = $this->getValidPath($path);

        $this->data = [];

        foreach ($paths as $path) {
            // Get file information
            $ext = pathinfo($path, PATHINFO_EXTENSION);
            $parser = $this->getParser($ext);

            // Try and load file
            $this->data = array_replace_recursive($this->data, $parser->parse($path));
        } // END foreach

        parent::__construct($this->data);
    }

    /**
     * Static method for loading a Konfig instance.
     *
     * @param  string | array $path
     * @return Konfig
     */
    public static function load($path = null)
    {
        return new static($path);
    }

    /**
     * Gets a parser for a given file extension
     *
     * @param  string $ext
     * @return Konfig\KonfigFileParser\IKonfigFileParser
     * @throws UnsupportedFormatException If `$path` is an unsupported file format
     */
    private function getParser($ext = null)
    {
        $parser = null;

        foreach ($this->_supportedFileParsers as $fileParser) {
            // require_once 'FileParser/' . $fileParser . '.php';

            $tempParser = new $fileParser;

            if (in_array($ext, $tempParser->getSupportedFileExtensions($ext), true)) {
                $parser = $tempParser;
                break;
{'fraction_non_alphanumeric': 0.11604714415231188, 'fraction_numerical': 0.0, 'mean_word_length': 2.2664692820133236, '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': '3547476', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1299, 'n_words': 291}