Il nécessite php-cli et readline, je l'ai utilisé avec mon php 5.3 mais je ne vois pas pourquoi un php 5 quelconque aurait un soucis à l'exécuter.
#! /usr/bin/php -q
<?php
error_reporting(E_ALL | E_STRICT);
$curdir = dirname(__FILE__);
//it will scan the files in /application/controllers/ so please check that is the directoy you want to look into
$files = glob($curdir . '/application/controllers/*.php');
for($i=0; $i<count($files); $i++) {
$error_state = false;
$text = '';
$content = file_get_contents($files[$i]);
$lines = explode("\n", $content);
$patterns = array();
$replaces = array();
foreach($lines as $numl=>$l) {
//This is the magic line, it will match for any occurence of something containing asciis with upper case letters and finishing with Action
//it will also ignore the class definition since in my case it was containing the word Action
if(!preg_match('`^class`', $l) && preg_match('`([a-z]+[A-Z].*)Action`', $l, $reg)) {
$error_state = true;
$text .= str_replace($curdir, '', $files[$i]) . ' contains an uppercase function here: '. $reg[1].'Action (line '.($numl+1).').' . "\n";
if(!in_array('`'.$reg[1].'Action`', $patterns)) {
array_push($patterns, '`'.$reg[1].'Action`');
array_push($replaces, strtolower($reg[1]) . 'Action');
}
}
}
if($error_state) {
echo $text;
$input = strtolower(substr(readline('Fix? YES/no: '), 0, 1));
if($input == 'y' || $input == '') {
file_put_contents($files[$i], preg_replace($patterns, $replaces, $content));
echo 'Fixing...' . "\n";
$i--;
} else {
die('GoodBye!' . "\n");
}
}
}
die('This is clean :)' . "\n");