<commit_before><?php /* © 2009 Akelos PHP Framework (LGPL'd licensed) - http://www.akelos.org/copyright */

array_shift($argv);
$options = $argv;

$path = array_shift($options);

if(is_file($path)){
    $files = array($path);
}else{
    $files = array();
    $dir_list = ak_dir($path, array('recurse' => true));
    foreach ($dir_list as $entry){
        $file = $path.$entry;
        if(is_file($file)){
            $files[] = $file;
        }
    }
}

if(ak_prompt("Did you backup these files?:".join("\n", $files), array('default'=>'yes')) == 'yes'){
    foreach ($files as $file){
        $php4_contents = file_get_contents($file);
        $php5_contents = convert_to_php5($php4_contents);

        echo "\n\n--------\nPHP5 file contents\n--------\n\n".$php5_contents."\n\n";
        if(ak_prompt("Do you want to replace $file with the above contents?", array('default'=>'yes')) == 'yes'){
            file_put_contents($file, $php5_contents);
        }else {
            echo "\nSkiping $file\n\n";
        }
    }
}else {
    echo "Take your time to backup your files as something might go wrong while converting to PHP5";
}


echo "\n";


function convert_to_php5($code){
    $replacements = array(
    '/&(\s?)new /' => '$1new ',
    '/(\s{4,})function /' => '$1public function ',
    '/([\(,])(\s?)&(\s?)\$/' => '$1$2$3$',
    '/(\s{4,})var(\s+)\$/' =>   '$1public$2$');

    foreach ($replacements as $k => $v){
        if(preg_match_all($k, $code, $matches)){
            $code = preg_replace($k, $v, $code);
        }
    }

    return $code;
}

function ak_dir($path, $options = array())
{
    $result = array();

    $path = rtrim($path, '/\\');
    $default_options = array(
    'files' => true,
    'dirs' => true,
    'recurse' => false,
    );

    $options = array_merge($default_options, $options);
<commit_msg>Preventing conversion to PHP5 of<commit_after><?php /* © 2009 Akelos PHP Framework (LGPL'd licensed) - http://www.akelos.org/copyright */

array_shift($argv);
$options = $argv;

$path = array_shift($options);

if(is_file($path)){
    $files = array($path);
}else{
    $files = array();
    $dir_list = ak_dir($path, array('recurse' => true));
    foreach ($dir_list as $entry){
        $file = $path.$entry;
        if(is_file($file)){
            $files[] = $file;
        }
    }
}

if(ak_prompt("Did you backup these files?:".join("\n", $files), array('default'=>'yes')) == 'yes'){
    foreach ($files as $file){
        $php4_contents = file_get_contents($file);
        $php5_contents = convert_to_php5($php4_contents);

        echo "\n\n--------\nPHP5 file contents\n--------\n\n".$php5_contents."\n\n";
        if(ak_prompt("Do you want to replace $file with the above contents?", array('default'=>'yes')) == 'yes'){
            file_put_contents($file, $php5_contents);
        }else {
            echo "\nSkiping $file\n\n";
        }
    }
}else {
    echo "Take your time to backup your files as something might go wrong while converting to PHP5";
}


echo "\n";


function convert_to_php5($code){
    $replacements = array(
    '/&(\s?)new /' => '$1new ',
    '/(\s{4,})function /' => '$1public function ',
    '/(?<!array)([\(,])(\s?)&(\s?)\$/' => '$1$2$3$',
    '/(\s{4,})var(\s+)\$/' =>   '$1public$2$');

    foreach ($replacements as $k => $v){
        if(preg_match_all($k, $code, $matches)){
            $code = preg_replace($k, $v, $code);
        }
    }

    return $code;
}

function ak_dir($path, $options = array())
{
    $result = array();

    $path = rtrim($path, '/\\');
    $default_options = array(
    'files' => true,
    'dirs' => true,
    'recurse' => false,
    );

    $options = array_merge($default_options, $options);

{'fraction_non_alphanumeric': 0.218639934976971, 'fraction_numerical': 0.01219181793551883, 'mean_word_length': 2.718026183282981, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2255552', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1295, 'n_words': 278}