Created
May 27, 2012 03:34
-
-
Save jrbasso/2802069 to your computer and use it in GitHub Desktop.
Update "use" to be 1 per class and ordered by name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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