Skip to content

Instantly share code, notes, and snippets.

@lolgzs
Created September 7, 2012 20:51
Show Gist options
  • Save lolgzs/3669516 to your computer and use it in GitHub Desktop.
Save lolgzs/3669516 to your computer and use it in GitHub Desktop.
MinimizeSingletonTest pour Johan
<?php
/**
* $result sera un tableau de lignes:
* nombre_occurences chemin/vers/fichier.php:Ma_Classe::instance
*/
exec('grep -ro --include="*.php" "\([A-Za-z_]*\)::instance" *|sort|uniq -c|grep -v 1', $result);
$infections = [];
array_map(
function($line) use (&$infections) {
preg_match_all('/([0-9])+ ([^:]+):([^:]+)::/', $line, $matches, PREG_SET_ORDER);
extract(array_combine(['match', 'number_of_occurences', 'filepath', 'classname'],
$matches[0]));
if (!isset($infections[$classname]))
$infections[$classname] = ['nb' => 0, 'files' => []];
$infections[$classname]['nb'] += $number_of_occurences;
$infections[$classname]['files'] []= $filepath;
},
$result);
print_r($infections);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment