<commit_before><?php
/**
 * zf2-sphinxsearch-tool
 *
 * @link        https://github.com/ripaclub/zf2-sphinxsearch-tool
 * @copyright   Copyright (c) 2014,
 *              <NAME> <leod<EMAIL>ato at gmail dot com>
 *              <NAME> <me at leonardograsso dot com>
 * @license     http://opensource.org/licenses/BSD-2-Clause Simplified BSD License
 */
namespace SphinxSearch\Tool\Controller;

use Zend\Config\Factory;

/**
 * Class ConfigTrait
 */
trait ConfigTrait
{
    /**
     * @param   string|null $file
     * @return  array
     */
    protected function getConfig($file = null)
    {
        // Config
        $config = $this->getServiceLocator()->get('Config');
        if (!isset($config['sphinxsearch'])) {
            throw new \InvalidArgumentException('Config not found with name: ' . $config);
        } else {
            $config = $config['sphinxsearch'];
            if (!is_null($file)) {
                $config = Factory::fromFile($file, true)->toArray();
            }
        }
        if (empty($config)) {
            throw new \RuntimeException('Invalid configuration');
        }

        return $config;
    }
}<commit_msg>Config object merge with defaults<commit_after><?php
/**
 * zf2-sphinxsearch-tool
 *
 * @link        https://github.com/ripaclub/zf2-sphinxsearch-tool
 * @copyright   Copyright (c) 2014,
 *              <NAME> <leodidonato at gmail dot com>
 *              <NAME> <me at leonardograsso dot com>
 * @license     http://opensource.org/licenses/BSD-2-Clause Simplified BSD License
 */
namespace SphinxSearch\Tool\Controller;

use Zend\Config\Factory;

/**
 * Class ConfigTrait
 */
trait ConfigTrait
{
    /**
     * @param   string|null $file
     * @return  array
     */
    protected function getConfig($file = null)
    {
        // Config
        $config = $this->getServiceLocator()->get('Config');
        if (!isset($config['sphinxsearch'])) {
            throw new \InvalidArgumentException('Config not found with name: ' . $config);
        } else {
            $config = $config['sphinxsearch'];
            if (!is_null($file)) {
                $config = array_merge($config['sphinxsearch'], Factory::fromFile($file, true)->toArray()); // FIXME: ?
            }
        }
        if (empty($config)) {
            throw new \RuntimeException('Invalid configuration');
        }

        return $config;
    }
}
{'fraction_non_alphanumeric': 0.14327855035819637, 'fraction_numerical': 0.0058997050147492625, 'mean_word_length': 2.203778677462888, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 18, 'https://': 2, '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': '7480193', 'n_tokens_mistral': 718, 'n_tokens_neox': 705, 'n_words': 148}