<commit_before><?php

require_once(__DIR__."/../functions/functions.inc");
require_once(__DIR__."/../functions/database.inc");
require_once(__DIR__."/../functions/users.inc");
require_once(__DIR__."/../functions/authentication.inc");
require_once(__DIR__."/../modules/event/functions/functions.inc");
require_once(__DIR__."/../modules/concom/functions/concom.inc");


function rand_word($len)
{
    $out = '';
    $c  = 'bcdfghjklmnprstvwz'; // consonants except hard to speak ones
    $v  = 'aeiou';              // vowels
    $a  = $c.$v;                // all

    for ($i = 0; $i <= $len; $i++) {
        $sy = $c[rand(0, strlen($c) - 1)];
        $sy .= $v[rand(0, strlen($v) - 1)];
        $sy .= $a[rand(0, strlen($a) - 1)];
        if (rand(0, 1) == 0) {
            $sy = ucfirst($sy);
        }
        $out .= $sy;
    }
    return $out;

}


function rand_name()
{
    $fn = '';
    /*.string.*/ $mn = null;
    $ln = '';

    $s = rand(0, 1) + 1;
    $fn = rand_word($s);

    if (rand(0, 1) > 0) {
        $s = rand(0, 1) + 1;
        $mn = rand_word($s);
    }

    $s = rand(0, 2) + 2;
    $ln  = rand_word($s);

    return [$fn, $mn, $ln];

}


function rand_address()
{
    $data = array();

    $num = rand(100, 9999);
    $s = rand(0, 3) + 2;
    $data['addressLine1'] = $num.' '.rand_word($s);
    $data['city'] = 'Minneapolis';
    $states = listStates();
    $randIndex = array_rand($states);
    $data['state'] = $states[$randIndex]['code'];
    $data['zipCode'] = strval(rand(10000, 99999));
    $counties = listCountries();
    $randIndex = array_rand($counties);
    $data['country'] = $counties[$randIndex]['id'];
    $data['phone1'] = strval(rand(1111111111, 9999999999));

    return $data;

}


function advance_cycles()
{
    $sql = "SELECT * FROM `AnnualCycles` WHERE DateTo = (SELECT MAX(DateTo) FROM `AnnualCycles`);";
    $result = \DB::run($sql);
    $value = $result->fetch();
    $last_end = $value['DateTo'];
    $last_start = $value['DateFrom'];
    $target = strtotime(' +183 day');
    while (strtotime($last_end) < $target) {
        print "Add new cycle\n";
        $last_start = date('Y-m-d', strtotime($last_start." + 365 day"));
        $last_end = date('Y-m-d', strtotime($last_end." + 365 day"));
        new_cycle($last_start, $last_end);
    }

}


function new_cycle($start, $end)
{
    print "$start - $end\n";
    $sql = <<<SQL
            INSERT INTO `AnnualCycles` 
                        (`AnnualCycleID`, `DateFrom`, `DateTo`) 
                        VALUES (NULL, "$start", "$end")
SQL;
    $result = \DB::run($sql);

}


function add_event()
{
    $event = \current_eventID();
    if ($event === null) {
        advance_cycles();
        print "Add new event\n";

        $event = (object)[
        "Name" => "WOW a test Event-Con",
        "Id" => -1,
        "From" => date('Y-m-d', strtotime(" + 180 day")),
        "To" => date('Y-m-d', strtotime(" + 183 day"))
        ];

        save_event($event);
    }

}

<commit_msg>Eliminate a smell<commit_after><?php

require_once(__DIR__."/../functions/functions.inc");
require_once(__DIR__."/../functions/database.inc");
require_once(__DIR__."/../functions/users.inc");
require_once(__DIR__."/../functions/authentication.inc");
require_once(__DIR__."/../modules/event/functions/functions.inc");
require_once(__DIR__."/../modules/concom/functions/concom.inc");


function rand_word($len)
{
    $out = '';
    $c  = 'bcdfghjklmnprstvwz'; // consonants except hard to speak ones
    $v  = 'aeiou';              // vowels
    $a  = $c.$v;                // all

    for ($i = 0; $i <= $len; $i++) {
        $sy = $c[rand(0, strlen($c) - 1)];
        $sy .= $v[rand(0, strlen($v) - 1)];
        $sy .= $a[rand(0, strlen($a) - 1)];
        if (rand(0, 1) == 0) {
            $sy = ucfirst($sy);
        }
        $out .= $sy;
    }
    return $out;

}


function rand_name()
{
    $fn = '';
    /*.string.*/ $mn = null;
    $ln = '';

    $s = rand(0, 1) + 1;
    $fn = rand_word($s);

    if (rand(0, 1) > 0) {
        $s = rand(0, 1) + 1;
        $mn = rand_word($s);
    }

    $s = rand(0, 2) + 2;
    $ln  = rand_word($s);

    return [$fn, $mn, $ln];

}


function rand_address()
{
    $data = array();

    $num = rand(100, 9999);
    $s = rand(0, 3) + 2;
    $data['addressLine1'] = $num.' '.rand_word($s);
    $data['city'] = 'Minneapolis';
    $states = listStates();
    $randIndex = array_rand($states);
    $data['state'] = $states[$randIndex]['code'];
    $data['zipCode'] = strval(rand(10000, 99999));
    $counties = listCountries();
    $randIndex = array_rand($counties);
    $data['country'] = $counties[$randIndex]['id'];
    $data['phone1'] = strval(rand(1111111111, 9999999999));

    return $data;

}


function advance_cycles()
{
    $sql = "SELECT * FROM `AnnualCycles` WHERE DateTo = (SELECT MAX(DateTo) FROM `AnnualCycles`);";
    $result = \DB::run($sql);
    $value = $result->fetch();
    $last_end = $value['DateTo'];
    $last_start = $value['DateFrom'];
    $target = strtotime(' +183 day');
    while (strtotime($last_end) < $target) {
        print "Add new cycle\n";
        $last_start = date('Y-m-d', strtotime($last_start." + 365 day"));
        $last_end = date('Y-m-d', strtotime($last_end." + 365 day"));
        new_cycle($last_start, $last_end);
    }

}


function new_cycle($start, $end)
{
    print "$start - $end\n";
    $sql = <<<SQL
            INSERT INTO `AnnualCycles` 
                        (`AnnualCycleID`, `DateFrom`, `DateTo`) 
                        VALUES (NULL, "$start", "$end")
SQL;
    \DB::run($sql);

}


function add_event()
{
    $event = \current_eventID();
    if ($event === null) {
        advance_cycles();
        print "Add new event\n";

        $event = (object)[
        "Name" => "WOW a test Event-Con",
        "Id" => -1,
        "From" => date('Y-m-d', strtotime(" + 180 day")),
        "To" => date('Y-m-d', strtotime(" + 183 day"))
        ];

        save_event($event);
    }

}


{'fraction_non_alphanumeric': 0.214190093708166, 'fraction_numerical': 0.02677376171352075, 'mean_word_length': 2.3902439024390243, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '2815238', 'n_tokens_mistral': 2376, 'n_tokens_neox': 2190, 'n_words': 435}