<commit_before><?php
namespace EditorconfigChecker\Editorconfig;

use Webmozart\Glob\Glob;
use Webmozart\PathUtil\Path;

class Editorconfig
{
    /**
     * Returns the editorconfig of a given path as an array
     *
     * @param string $editorconfigPath
     * @return array
     */
    protected function getRulesAsArray(string $editorconfigPath) : array
    {
        return parse_ini_file($editorconfigPath, true);
    }

    /**
     * Merge editorconfig rules for a given file
     * from an array of editorconfig rules
     *
     * @param string $fileName
     * @param array $editorconfig
     * @return array
     */
    protected function mergeRulesForFile(string $fileName, array $editorconfig) : array
    {
        return array_reduce(array_keys($editorconfig), function ($carry, $pattern) use ($editorconfig, $fileName) {
            $rules = $editorconfig[$pattern];

            return $pattern === 'root' ? ['root' => $editorconfig[$pattern]] : (
                Glob::match(sprintf('%s/%s', getcwd(), $fileName), Path::makeAbsolute('**/' . $pattern, getcwd())) ?
                    array_merge($carry, $rules) : $carry
            );
        }, []);
    }

    /**
     * Return the nearest matching editorconfig rules
     *
     * @param string $filePath
     * @param string $fileBasename<commit_msg>BUGFIX: Patterns never match any file under Windows<commit_after><?php
namespace EditorconfigChecker\Editorconfig;

use Webmozart\Glob\Glob;
use Webmozart\PathUtil\Path;

class Editorconfig
{
    /**
     * Returns the editorconfig of a given path as an array
     *
     * @param string $editorconfigPath
     * @return array
     */
    protected function getRulesAsArray(string $editorconfigPath) : array
    {
        return parse_ini_file($editorconfigPath, true);
    }

    /**
     * Merge editorconfig rules for a given file
     * from an array of editorconfig rules
     *
     * @param string $fileName
     * @param array $editorconfig
     * @return array
     */
    protected function mergeRulesForFile(string $fileName, array $editorconfig) : array
    {
        return array_reduce(array_keys($editorconfig), function ($carry, $pattern) use ($editorconfig, $fileName) {
            $rules = $editorconfig[$pattern];

            return $pattern === 'root' ? ['root' => $editorconfig[$pattern]] : (
                Glob::match(
                    Path::normalize(sprintf('%s/%s', getcwd(), $fileName)),
                    Path::makeAbsolute('**/' . $pattern, getcwd())
                ) ? array_merge($carry, $rules) : $carry
            );
        }, []);
    }

    /**
     * Return the nearest matching editorconfig rules
     *
     * @param string $filePath
     * @param string $fileBasename
{'fraction_non_alphanumeric': 0.11929952572053995, 'fraction_numerical': 0.0, 'mean_word_length': 2.5426356589147288, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '672450', 'n_tokens_mistral': 765, 'n_tokens_neox': 771, 'n_words': 199}