Skip to content

Instantly share code, notes, and snippets.

@jrbasso
Created May 27, 2012 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrbasso/2802069 to your computer and use it in GitHub Desktop.
Save jrbasso/2802069 to your computer and use it in GitHub Desktop.
Update "use" to be 1 per class and ordered by name
<?php
$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__));
while ($dir->valid()) {
$filename = $dir->key();
if (substr($filename, -4) !== '.php' || strpos($filename, '.git')) {
$dir->next();
continue;
}
$file = file_get_contents($filename);
$file = preg_replace_callback('/^use ([^;]+(,[^;]+))+;/m', function ($matches) {
$classes = explode(',', $matches[1]);
$classes = array_map(function ($class) {
return 'use ' . trim($class) . ';';
}, $classes);
sort($classes);
return implode("\n", $classes);
}, $file);
file_put_contents($filename, $file);
$dir->next();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment