<commit_before><?php
namespace Hal\Application\Config;

/**
 * Class Validator
 * @package Hal\Application\Config
 */
class Validator
{

    /**
     * @param Config $config
     * @throws ConfigException
     */
    public function validate(Config $config)
    {

        // required
        if (!$config->has('files')) {
            throw new ConfigException('Directory to parse is missing or incorrect');
        }
        foreach ($config->get('files') as $dir) {
            if (!file_exists($dir)) {
                throw new ConfigException(sprintf('Directory %s does not exist', $dir));
            }
        }

        // extensions
        if(!$config->has('extensions')) {
            $config->set('extensions', 'php,inc');
        }
        $config->set('extensions', explode(',', $config->get('extensions')));

        // extensions
        if(!$config->has('exclude')) {
            $config->set('exclude', 'vendor,test,Test,tests,Tests,testing,Testing,bower_components,node_modules');
        }
        $config->set('exclude', array_filter(explode(',', $config->get('exclude'))));
    }

    /**
     * @return string
     */
    public function help()
    {
        return <<<EOT
Usage:

    phpmetrics [--report-html=<directory>] [--exclude=<directory>] [--git=</path/to/git_binary>] [--quiet] <directory>

Required:

    <directory>                         List of directories to parse, separated by a comma (,)<commit_msg>added 'cache' in the default exclusion list<commit_after><?php
namespace Hal\Application\Config;

/**
 * Class Validator
 * @package Hal\Application\Config
 */
class Validator
{

    /**
     * @param Config $config
     * @throws ConfigException
     */
    public function validate(Config $config)
    {

        // required
        if (!$config->has('files')) {
            throw new ConfigException('Directory to parse is missing or incorrect');
        }
        foreach ($config->get('files') as $dir) {
            if (!file_exists($dir)) {
                throw new ConfigException(sprintf('Directory %s does not exist', $dir));
            }
        }

        // extensions
        if(!$config->has('extensions')) {
            $config->set('extensions', 'php,inc');
        }
        $config->set('extensions', explode(',', $config->get('extensions')));

        // extensions
        if(!$config->has('exclude')) {
            $config->set('exclude', 'vendor,test,Test,tests,Tests,testing,Testing,bower_components,node_modules,cache');
        }
        $config->set('exclude', array_filter(explode(',', $config->get('exclude'))));
    }

    /**
     * @return string
     */
    public function help()
    {
        return <<<EOT
Usage:

    phpmetrics [--report-html=<directory>] [--exclude=<directory>] [--git=</path/to/git_binary>] [--quiet] <directory>

Required:

    <directory>                         List of directories to parse, separated by a comma (,)
{'fraction_non_alphanumeric': 0.16552433173406442, 'fraction_numerical': 0.0, 'mean_word_length': 2.336, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 33, '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': '3299897', 'n_tokens_mistral': 832, 'n_tokens_neox': 795, 'n_words': 172}