<commit_before><?php

/**
 * JBZoo Toolbox - Composer-Graph
 *
 * This file is part of the JBZoo Toolbox project.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @package    Composer-Graph
 * @license    MIT
 * @copyright  Copyright (C) JBZoo.com, All rights reserved.
 * @link       https://github.com/JBZoo/Composer-Graph
 */

$packageName = isset($GLOBALS["argv"][1]) ? $GLOBALS["argv"][1] : 'Testing';

if (!$packageName || $packageName === '__CHANGE_ME__') {
    echo 'Undefined package name! Plz, check config' . PHP_EOL;
    exit(1);
}

$packageName = ucfirst(trim($packageName));
$namespace = str_replace('-', '', $packageName);

global $config;

$config = [
    'root'    => realpath('.'),
    'exclude' => [
        '.',
        '..',
        '.git',
        '.idea',
        'vendor',
        'build',
        pathinfo(__FILE__, PATHINFO_BASENAME),
    ],
    'defines' => [
        '__PACKAGE__'        => $packageName,
        '__NS__'             => $namespace,
        'jbzoo/skeleton-php' => 'jbzoo/' . strtolower($packageName),
    ],
];


/**********************************************************************************************************************/

/**
 * @param $path
 * @return null|string
 */
function openFile($path)
{
    $contents = null;

    if ($realPath = realpath($path)) {
        $handle = fopen($path, "rb");
        $contents = fread($handle, filesize($path));
        fclose($handle);
    }

    return $contents;
}

/**
 * @param       $dir
 * @param null  $filter
 * @param array $results
 * @return array
 */
function getFileList($dir, $filter = null, &$results = [])
{
    $files = scandir($dir);

    global $config;

    foreach ($files as $key => $value) {
        $path = $dir . DIRECTORY_SEPARATOR . $value;

        if (!is_dir($path) && !in_array($value, $config['exclude'], true)) {
            if ($filter) {
                if (preg_match('#' . $filter . '#iu', $path)) {
                    $results[] = realpath($path);
                }
            } else {
                $results[] = realpath($path);
            }

        } elseif (is_dir($path) && !in_array($value, $config['exclude'], true)) {
            getFileList($path, $filter, $results);
        }
    }

    return $results;
}


/********** Replace all files *****************************************************************************************/
$list = getFileList($config['root']);
foreach ($list as $file) {
    $content = openFile($file);

    foreach ($config['defines'] as $const => $value) {
        $content = str_replace($const, $value, $content);
    }

    if (strpos($file, 'Makefile')) {
        $regexp = '/\n# Cutline.*/ius';
        $content = preg_replace($regexp, '', $content);
    }

    if (strpos($file, '.travis.yml')) {
        $content = str_replace("make new-project NAME=\"Rulezzz-Test\"\n", '', $content);
    }

    file_put_contents($file, $content);
}


/********** Change Readme file ****************************************************************************************/
rename(
    $config['root'] . '/README.dist.md',
    $config['root'] . '/README.md'
);

rename(
    $config['root'] . "/__NS__CodestyleTest.php",
    $config['root'] . "/{$namespace}CodestyleTest.php"
);

rename(
    $config['root'] . "/__NS__CopyrightTest.php",
    $config['root'] . "/{$namespace}CopyrightTest.php"
);


/********** Self-destruction ******************************************************************************************/
@unlink(__FILE__);
<commit_msg>Fixes<commit_after><?php

/**
 * JBZoo Toolbox - Composer-Graph
 *
 * This file is part of the JBZoo Toolbox project.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @package    Composer-Graph
 * @license    MIT
 * @copyright  Copyright (C) <EMAIL>, All rights reserved.
 * @link       https://github.com/JBZoo/Composer-Graph
 */

$packageName = isset($GLOBALS["argv"][1]) ? $GLOBALS["argv"][1] : 'Testing';

if (!$packageName || $packageName === '__CHANGE_ME__') {
    echo 'Undefined package name! Plz, check config' . PHP_EOL;
    exit(1);
}

$packageName = ucfirst(trim($packageName));
$namespace = str_replace('-', '', $packageName);

global $config;

$config = [
    'root'    => realpath('.'),
    'exclude' => [
        '.',
        '..',
        '.git',
        '.idea',
        'vendor',
        'build',
        pathinfo(__FILE__, PATHINFO_BASENAME),
    ],
    'defines' => [
        '__PACKAGE__'        => $packageName,
        '__NS__'             => $namespace,
        'jbzoo/skeleton-php' => 'jbzoo/' . strtolower($packageName),
    ],
];


/**********************************************************************************************************************/

/**
 * @param $path
 * @return null|string
 */
function openFile($path)
{
    $contents = null;

    if ($realPath = realpath($path)) {
        $handle = fopen($path, "rb");
        $contents = fread($handle, filesize($path));
        fclose($handle);
    }

    return $contents;
}

/**
 * @param       $dir
 * @param null  $filter
 * @param array $results
 * @return array
 */
function getFileList($dir, $filter = null, &$results = [])
{
    $files = scandir($dir);

    global $config;

    foreach ($files as $key => $value) {
        $path = $dir . DIRECTORY_SEPARATOR . $value;

        if (!is_dir($path) && !in_array($value, $config['exclude'], true)) {
            if ($filter) {
                if (preg_match('#' . $filter . '#iu', $path)) {
                    $results[] = realpath($path);
                }
            } else {
                $results[] = realpath($path);
            }

        } elseif (is_dir($path) && !in_array($value, $config['exclude'], true)) {
            getFileList($path, $filter, $results);
        }
    }

    return $results;
}


/********** Replace all files *****************************************************************************************/
$list = getFileList($config['root']);
foreach ($list as $file) {
    $content = openFile($file);

    foreach ($config['defines'] as $const => $value) {
        $content = str_replace($const, $value, $content);
    }

    if (strpos($file, 'Makefile')) {
        $regexp = '/\n# Cutline.*/ius';
        $content = preg_replace($regexp, '', $content);
    }

    if (strpos($file, '.travis.yml')) {
        $content = str_replace("make new-project NAME=\"Rulezzz-Test\"\n", '', $content);
    }

    file_put_contents($file, $content);
}


/********** Change Readme file ****************************************************************************************/
rename(
    $config['root'] . "/src/__NS__.php",
    $config['root'] . "/src/{$namespace}.php"
);

rename(
    $config['root'] . "/tests/__NS__CodestyleTest.php",
    $config['root'] . "/tests/{$namespace}CodestyleTest.php"
);

rename(
    $config['root'] . "/tests/__NS__CopyrightTest.php",
    $config['root'] . "/tests/{$namespace}CopyrightTest.php"
);

rename(
    $config['root'] . '/README.dist.md',
    $config['root'] . '/README.md'
);

/********** Self-destruction ******************************************************************************************/
@unlink(__FILE__);

{'fraction_non_alphanumeric': 0.28188286808976465, 'fraction_numerical': 0.0008210180623973727, 'mean_word_length': 2.963665943600868, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 20, 'https://': 2, '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': '317099', 'n_tokens_mistral': 2264, 'n_tokens_neox': 2191, 'n_words': 447}