<commit_before><?php

require_once __DIR__ . '/autoload.php';
require_once __DIR__ . '/common.php';

class Searcher {
    function __construct(SearchSettings $settings) {
        $this->settings = $settings;
        $this->filetypes = new FileTypes();
        $this->results = array();
        $this->validate_settings();
    }

    private function validate_settings() {
        if (strlen($this->settings->startpath) == 0) {
            throw new SearchException('Startpath not defined');
        }
        if (!file_exists($this->settings->startpath)) {
            throw new SearchException('Startpath not found');
        }
        if (count($this->settings->searchpatterns) == 0) {
            throw new SearchException('No search patterns defined');
        }
    }

    private function matches_any_pattern(string $s, array $patterns): bool {
        foreach ($patterns as $pattern) {
            $pattern = '/' . $pattern . '/';
            if (preg_match_all($pattern, $s))
                return true;
        }
        return false;
    }

    private function any_matches_any_pattern(array $slist, array $patterns): bool {
        foreach ($slist as $s) {
            if ($this->matches_any_pattern($s, $patterns))
                return true;<commit_msg>Add is_readable startpath check<commit_after><?php

require_once __DIR__ . '/autoload.php';
require_once __DIR__ . '/common.php';

class Searcher {
    function __construct(SearchSettings $settings) {
        $this->settings = $settings;
        $this->filetypes = new FileTypes();
        $this->results = array();
        $this->validate_settings();
    }

    private function validate_settings() {
        if (strlen($this->settings->startpath) == 0) {
            throw new SearchException('Startpath not defined');
        }
        if (!file_exists($this->settings->startpath)) {
            throw new SearchException('Startpath not found');
        }
        if (!is_readable($this->settings->startpath)) {
            throw new SearchException('Startpath not readable');
        }
        if (count($this->settings->searchpatterns) == 0) {
            throw new SearchException('No search patterns defined');
        }
    }

    private function matches_any_pattern(string $s, array $patterns): bool {
        foreach ($patterns as $pattern) {
            $pattern = '/' . $pattern . '/';
            if (preg_match_all($pattern, $s))
                return true;
        }
        return false;
    }

    private function any_matches_any_pattern(array $slist, array $patterns): bool {
        foreach ($slist as $s) {
            if ($this->matches_any_pattern($s, $patterns))
                return true;
{'fraction_non_alphanumeric': 0.12849162011173185, 'fraction_numerical': 0.0014897579143389199, 'mean_word_length': 2.3366459627329195, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '3485466', 'n_tokens_mistral': 739, 'n_tokens_neox': 724, 'n_words': 175}