<commit_before><?php
namespace RandomQuoteBot\Library\Slack;

use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;

class SlackConfig
{
    const KEY_ROOT = 'slack';
    const KEY_API_KEY = 'api_key';
    const KEY_CHANNELS = 'channels';
    const KEY_USERS = 'users';
    const KEY_USER_ID = 'id';
    const KEY_USER_NAME = 'name';
    const KEY_USER_IMAGE = 'image';

    /**
     * @var
     */
    private $options;

    /**
     * @param $fileName
     */
    public function __construct($fileName)
    {
        $config = self::parseYml($fileName);
        if (!isset($config[self::KEY_ROOT])) {
            throw new ParseException('Missing root key: ' . self::KEY_ROOT);
        }
        $this->options = $config[self::KEY_ROOT];
    }

    /**
     * @return null|string
     */
    public function getApiKey()
    {
        return isset($this->options[self::KEY_API_KEY]) ? $this->options[self::KEY_API_KEY] : null;
    }
    
    /**
     * @return array
     */
    public function getUsers()
    {
        return isset($this->options[self::KEY_USERS]) ? $this->options[self::KEY_USERS] : [];
    }

    /**
     * @param $name
     * @return null|array
     */
    public function getUserByName($name)
    {
        foreach ($this->options[self::KEY_USERS] as $user) {
            if ($user[self::KEY_USER_NAME] == $name) return $user;
        }
        
        return null;
    }

    /**
     * @param $id
     * @return null|array
     */
    public function getUserById($id)
    {
        foreach ($this->options[self::KEY_USERS] as $user) {
            if ($user[self::KEY_USER_ID] == $id) return $user;
        }

        return null;
    }
    
    /**
     * @return array
     */
    public function getChannel()
    {
        return isset($this->options[self::KEY_CHANNELS]) ? $this->options[self::KEY_CHANNELS] : [];
    }

    /**
     * @param $fileName
     * @return mixed
     */
    protected static function parseYml($fileName)
    {
        if (!file_exists($fileName)) {
            throw new FileNotFoundException($fileName);
        }

        return Yaml::parse($fileName);
    }
}<commit_msg>[#1] update to use base Exception instead of missing class<commit_after><?php
namespace RandomQuoteBot\Library\Slack;

use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;

class SlackConfig
{
    const KEY_ROOT = 'slack';
    const KEY_API_KEY = 'api_key';
    const KEY_CHANNELS = 'channels';
    const KEY_USERS = 'users';
    const KEY_USER_ID = 'id';
    const KEY_USER_NAME = 'name';
    const KEY_USER_IMAGE = 'image';

    /**
     * @var
     */
    private $options;

    /**
     * @param $fileName
     */
    public function __construct($fileName)
    {
        $config = self::parseYml($fileName);
        if (!isset($config[self::KEY_ROOT])) {
            throw new ParseException('Missing root key: ' . self::KEY_ROOT);
        }
        $this->options = $config[self::KEY_ROOT];
    }

    /**
     * @return null|string
     */
    public function getApiKey()
    {
        return isset($this->options[self::KEY_API_KEY]) ? $this->options[self::KEY_API_KEY] : null;
    }
    
    /**
     * @return array
     */
    public function getUsers()
    {
        return isset($this->options[self::KEY_USERS]) ? $this->options[self::KEY_USERS] : [];
    }

    /**
     * @param $name
     * @return null|array
     */
    public function getUserByName($name)
    {
        foreach ($this->options[self::KEY_USERS] as $user) {
            if ($user[self::KEY_USER_NAME] == $name) return $user;
        }
        
        return null;
    }

    /**
     * @param $id
     * @return null|array
     */
    public function getUserById($id)
    {
        foreach ($this->options[self::KEY_USERS] as $user) {
            if ($user[self::KEY_USER_ID] == $id) return $user;
        }

        return null;
    }
    
    /**
     * @return array
     */
    public function getChannel()
    {
        return isset($this->options[self::KEY_CHANNELS]) ? $this->options[self::KEY_CHANNELS] : [];
    }

    /**
     * @param $fileName
     * @return mixed
     */
    protected static function parseYml($fileName)
    {
        if (!file_exists($fileName)) {
            throw new \Exception($fileName);
        }

        return Yaml::parse($fileName);
    }
}
{'fraction_non_alphanumeric': 0.14450354609929078, 'fraction_numerical': 0.00022163120567375886, 'mean_word_length': 2.2584837545126355, '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': '5824097', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1425, 'n_words': 265}