<commit_before><?php

/**
 * @param $path
 * @param $baseClassName
 * @param $dummy
 */
function parseFile($path, $baseClassName, $dummy)
{
    echo 'Process ' . $path . "\n";
    $require = [];
    $code = file_get_contents($path);
    //$pattern = '/if \(\!class_exists\(\"([a-zA-Z]+)\", FALSE\)\) \{(.*)\}\}/um';
    $pattern = '/if \(!class_exists\("([a-zA-Z_]+)", false\)\) {\s(.*?\s*}\s*})\s*}/ms';

    preg_match_all($pattern, $code, $matches);

    $count = count($matches[0]);
    if ($count > 0) {
        for ($i = 0; $i < $count; $i++) {
            $className = $matches[1][$i];
            echo 'Found ' . $className . "\n";
            $classCode = $matches[2][$i];

            if ($className == $baseClassName) {
                echo "It's a base class\n";
                $result = str_ireplace(
                    '%require%',
                    'require_once(\'' . $className . '.require.php\');' . PHP_EOL,
                    $dummy
                );
            } else {
                echo "It's a required class\n";
                $result = str_ireplace('%require%', '', $dummy);
                $require[] = $className;
            }
            echo 'Write class file for ' . $className . "\n";
            $newPath = 'Google/Api/Ads/AdWords/v201506/classes/' . $className . '.php';
            file_put_contents(
                $newPath,
                str_ireplace('%code%', $classCode, $result)
            );

            //$code = str_ireplace($mecho "Right new class " . $className . "\n";atches[0][$i], "", $code);
        }
    }
    $requireCode = '';
    foreach ($require as $className) {
        echo 'Add require ' . $className . "\n";
        $requireCode .= 'require_once(\'' . $className . '.php\');' . PHP_EOL;
    }
    echo 'Write required file for ' . $baseClassName . "\n";
    file_put_contents(
        'Google/Api/Ads/AdWords/v201506/classes/' . $baseClassName . '.require.php',
        '<?php' . PHP_EOL . $requireCode
    );
    //unlink($path);
}

$dummy = file_get_contents('Dummy.php.txt');

$handle = opendir('Google/Api/Ads/AdWords/v201506/');
$files = readdir($handle);
while (false !== ($entry = readdir($handle))) {
    if (strpos($entry, 'Service.php')) {
        $path = 'Google/Api/Ads/AdWords/v201506/' . $entry;
        parseFile($path, str_ireplace('.php', '', $entry), $dummy);
    }
}<commit_msg>extract version<commit_after><?php

/**
 * @param $path
 * @param $baseClassName
 * @param $dummy
 */


function parseFile($version, $path, $baseClassName, $dummy)
{
    echo 'Process ' . $path . "\n";
    $require = [];
    $code = file_get_contents($path);
    //$pattern = '/if \(\!class_exists\(\"([a-zA-Z]+)\", FALSE\)\) \{(.*)\}\}/um';
    $pattern = '/if \(!class_exists\("([a-zA-Z_]+)", false\)\) {\s(.*?\s*}\s*})\s*}/ms';

    preg_match_all($pattern, $code, $matches);

    $count = count($matches[0]);
    if ($count > 0) {
        for ($i = 0; $i < $count; $i++) {
            $className = $matches[1][$i];
            echo 'Found ' . $className . "\n";
            $classCode = $matches[2][$i];

            if ($className == $baseClassName) {
                echo "It's a base class\n";
                $result = str_ireplace(
                    '%require%',
                    'require_once(\'' . $className . '.require.php\');' . PHP_EOL,
                    $dummy
                );
            } else {
                echo "It's a required class\n";
                $result = str_ireplace('%require%', '', $dummy);
                $require[] = $className;
            }
            echo 'Write class file for ' . $className . "\n";
            $newPath = 'Google/Api/Ads/AdWords/' . $version . '/classes/' . $className . '.php';
            file_put_contents(
                $newPath,
                str_ireplace('%code%', $classCode, $result)
            );

            //$code = str_ireplace($mecho "Right new class " . $className . "\n";atches[0][$i], "", $code);
        }
    }
    $requireCode = '';
    foreach ($require as $className) {
        echo 'Add require ' . $className . "\n";
        $requireCode .= 'require_once(\'' . $className . '.php\');' . PHP_EOL;
    }
    echo 'Write required file for ' . $baseClassName . "\n";
    file_put_contents(
        'Google/Api/Ads/AdWords/' . $version . '/classes/' . $baseClassName . '.require.php',
        '<?php' . PHP_EOL . $requireCode
    );
    //unlink($path);
}

$version = 'v201509';

$dummy = file_get_contents('Dummy.php.txt');

$handle = opendir('Google/Api/Ads/AdWords/' . $version . '/');
$files = readdir($handle);
while (false !== ($entry = readdir($handle))) {
    if (strpos($entry, 'Service.php')) {
        $path = 'Google/Api/Ads/AdWords/' . $version . '/' . $entry;
        parseFile($version, $path, str_ireplace('.php', '', $entry), $dummy);
    }
}
{'fraction_non_alphanumeric': 0.2101884448125906, 'fraction_numerical': 0.008697452888796852, 'mean_word_length': 1.9308252427184467, 'pattern_counts': {'":': 0, '<': 9, '<?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': '6392623', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1572, 'n_words': 313}