<commit_before><?php

define("DEBUG", true);

if (DEBUG) {
    error_reporting(E_ALL);
}

// load libraries
require_once 'vendor/autoload.php';
use \Github\Client;

if(!is_file("config.json")) {
    die("You have not created a config.json file yet.\n");
}

require_once 'config.php';

class Bot {
    protected const TIDY_CONFIG = Array();
    protected const REQUIRED_JS_FILE = "/materialize\.(min\.)?js)/";
    protected const REQUIRED_CSS_FILE = "/materialize\.(min\.)?css/";
    public const PROJECT_NAME = "materialize";
    protected const JSHINT_HEADER_LENGTH = 15;
    protected const JS_HEADER_LOC = "jshint_header.js";
    protected const SPECIFIC_PAIR_CHECKS = Array(
        "chips" => ".material_chip(",
        "carousel" => ".carousel(",
        "tap-target" => ".tapTarget(",
        "parallax-container" => ".parallax(",
        "scrollspy" => ".scrollSpy(",
        "side-nav" => ".sideNav("
        );
    protected $client;
    public $repository;
    public $username;
    protected $openIssues, $closedIssues;

    protected $highestAnalyzedIssueNumber=0;

    public function __construct($repository) {
        $this->repository = $repository;

        $this->client = new Client();

        $this->login();

        $this->refreshIssues();

        $this->updateIssueCounter();

        echo "Bot started...running as of issue ".$this->highestAnalyzedIssueNumber."\n";

        $this->highestAnalyzedIssueNumber = 38;

        $this->run();
    }

    protected function login() {
        // login
        $authentication = json_decode(file_get_contents("config.json"), true);
        $this->username = $authentication["username"];
        $this->client->authenticate($authentication["username"], $authentication["password"], Client::AUTH_HTTP_PASSWORD);
    }

    protected function refreshIssues() {
        $this->closedIssues = $this->client->api("issue")->all($this->repository[0], $this->repository[1], Array("state" => "closed"));
        $this->openIssues = $this->client->api("issue")->all($this->repository[0], $this->repository[1], Array("state" => "open"));
    }

    protected function run() {
        while (true) {
            $this->refreshIssues();

            $this->analyzeOpenIssues();
            
            sleep(2);
        }
    }

    public function getUnanalyzedIssues() : array {
        // TODO: I know there is a way better way to do this
        // that uses a for/while loop instead
        return array_filter($this->openIssues, function(array $issue) {
            return $this->highestAnalyzedIssueNumber < $issue["number"];
        });
    }

    public static function getHTMLErrors(string $in) : array {
        $tidy = new Tidy();
        $tidy->parseString($in, self::TIDY_CONFIG);
        return explode("\n", $tidy->errorBuffer);
    }
<commit_msg>debug line, sleep time constant<commit_after><?php

define("DEBUG", true);

if (DEBUG) {
    error_reporting(E_ALL);
}

// load libraries
require_once 'vendor/autoload.php';
use \Github\Client;

if(!is_file("config.json")) {
    die("You have not created a config.json file yet.\n");
}

require_once 'config.php';

class Bot {
    protected const TIDY_CONFIG = Array();
    protected const REQUIRED_JS_FILE = "/materialize\.(min\.)?js)/";
    protected const REQUIRED_CSS_FILE = "/materialize\.(min\.)?css/";
    public const PROJECT_NAME = "materialize";
    protected const JSHINT_HEADER_LENGTH = 15;
    protected const JS_HEADER_LOC = "jshint_header.js";
    protected const SLEEP_TIME = 2; // seconds
    protected const SPECIFIC_PAIR_CHECKS = Array(
        "chips" => ".material_chip(",
        "carousel" => ".carousel(",
        "tap-target" => ".tapTarget(",
        "parallax-container" => ".parallax(",
        "scrollspy" => ".scrollSpy(",
        "side-nav" => ".sideNav("
        );
    protected $client;
    public $repository;
    public $username;
    protected $openIssues, $closedIssues;

    protected $highestAnalyzedIssueNumber=0;

    public function __construct($repository) {
        $this->repository = $repository;

        $this->client = new Client();

        $this->login();

        $this->refreshIssues();

        $this->updateIssueCounter();

        echo "Bot started...running as of issue ".$this->highestAnalyzedIssueNumber."\n";

        $this->run();
    }

    protected function login() {
        // login
        $authentication = json_decode(file_get_contents("config.json"), true);
        $this->username = $authentication["username"];
        $this->client->authenticate($authentication["username"], $authentication["password"], Client::AUTH_HTTP_PASSWORD);
    }

    protected function refreshIssues() {
        $this->closedIssues = $this->client->api("issue")->all($this->repository[0], $this->repository[1], Array("state" => "closed"));
        $this->openIssues = $this->client->api("issue")->all($this->repository[0], $this->repository[1], Array("state" => "open"));
    }

    protected function run() {
        while (true) {
            $this->refreshIssues();

            $this->analyzeOpenIssues();
            
            sleep(self::SLEEP_TIME);
        }
    }

    public function getUnanalyzedIssues() : array {
        // TODO: I know there is a way better way to do this
        // that uses a for/while loop instead
        return array_filter($this->openIssues, function(array $issue) {
            return $this->highestAnalyzedIssueNumber < $issue["number"];
        });
    }

    public static function getHTMLErrors(string $in) : array {
        $tidy = new Tidy();
        $tidy->parseString($in, self::TIDY_CONFIG);
        return explode("\n", $tidy->errorBuffer);
    }

{'fraction_non_alphanumeric': 0.15664138295995766, 'fraction_numerical': 0.00317516316810725, 'mean_word_length': 2.8809034907597537, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 76, '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': '3467656', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1677, 'n_words': 353}