<commit_before><?php

/**
 * @file
 */

namespace Drupal\AppConsole;

class Config
{
    /** @var Symfony\Component\Yaml\Parser $parser */
    protected $parser;

    protected $root_path;

    protected $config;

    public function __construct($parser, $root_path)
    {
        $this->parser = $parser;
        $this->root_path = $root_path;
        $this->mergeConfig();
    }

    protected function readYamlFile($path_file)
    {
        if (file_exists($path_file)) {
            return $this->parser->parse(file_get_contents($path_file));
        } else {
            return [];
        }
    }

    protected function mergeConfig()
    {
        $baseConfig = $this->getBaseConfig();
        $userConfig = $this->getUserConfig();

        $this->config = array_replace_recursive($baseConfig, $userConfig);
    }

    protected function getBaseConfig()
    {
        return $this->readYamlFile($this->root_path . '/config.yml');
    }

    protected function getUserConfig()
    {
        $userConfig = $this->readYamlFile(
          $this->getUserHomeDir() . '/.console/config.yml'
        );
        return $userConfig;
    }

    protected function getUserHomeDir()
    {
        return rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '/\\');
    }

    public function get($key, $default = '')
    {
        if (!$key) {
            return $default;
        }

        $config = $this->config;
        $items = explode('.', $key);

        if (!$items) {
            return $default;
        }

        foreach ($items as $item) {
            if (!$config[$item]) {
                return $default;
            }
            $config = $config[$item];
        }

        return $config;
    }<commit_msg>#516 Remove UserConfig methods<commit_after><?php
/**
 * @file
 * Contains \Drupal\AppConsole\Config.
 */

namespace Drupal\AppConsole;

use Symfony\Component\Yaml\Parser;

class Config
{
    protected $file;

    protected $parser;

    protected $config;

    public function __construct($file = null)
    {
        $this->parser = new Parser();
        if ($file) {
            $this->file = $file;
            $this->config = $this->readYamlFile($file);
        }
    }

    public function readYamlFile($file = null)
    {
        if (is_null($file)) {
            return [];
        }

        if (file_exists($file)) {
            return $this->parser->parse(file_get_contents($file));
        } else {
            return [];
        }
    }

    public function get($key, $default = '')
    {
        if (!$key) {
            return $default;
        }

        $config = $this->config;
        $items = explode('.', $key);

        if (!$items) {
            return $default;
        }

        foreach ($items as $item) {
            if (!$config[$item]) {
                return $default;
            }
            $config = $config[$item];
        }

        return $config;
    }
{'fraction_non_alphanumeric': 0.14521679284239505, 'fraction_numerical': 0.0010323468685478321, 'mean_word_length': 1.7580645161290323, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '2918372', 'n_tokens_mistral': 867, 'n_tokens_neox': 844, 'n_words': 167}