Created
June 20, 2013 19:30
-
-
Save msonnabaum/5825849 to your computer and use it in GitHub Desktop.
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 | |
require './tests/bootstrap.php'; | |
function lib_files() { | |
$module_roots = array(); | |
foreach (scandir('./modules') as $module) { | |
if (!in_array($module, array('.', '..')) && is_dir("./modules/$module")) { | |
$module_roots[$module] = "./modules/$module/lib"; | |
} | |
} | |
$core_root = './lib'; | |
$lib_files = array_filter(array_map(function ($dir) { | |
if (is_dir($dir)) { | |
$all_files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir)); | |
$files = array_filter(array_map(function($file) { | |
return $file->getExtension() === 'php' ? $file->getPathname() : NULL; | |
}, iterator_to_array($all_files, false))); | |
return $files; | |
} | |
}, $module_roots + array($core_root))); | |
return call_user_func_array('array_merge', $lib_files); | |
} | |
function get_parent($classname) { | |
try { | |
$class = new \ReflectionClass($classname); | |
$parent = $class->getParentClass(); | |
if (!$parent) return FALSE; | |
return $parent->getName(); | |
} | |
catch (ReflectionException $e) { | |
return FALSE; | |
} | |
} | |
function get_inheritance_chain($classname) { | |
$parents = array(); | |
$parent = get_parent($classname); | |
while ($parent) { | |
$parents[] = $parent; | |
$parent = get_parent($parent); | |
} | |
return $parents; | |
} | |
function files_to_classes($files) { | |
return array_filter(array_map(function ($file) { | |
if (strpos($file, '/Tests/') !== false) return false; | |
if (strpos($file, 'Simpletest') !== false) return false; | |
if (strpos($file, 'simpletest') !== false) return false; | |
list($loader_root, $filename) = explode('lib', $file); | |
return str_replace('.php', '', str_replace('/', '\\', $filename)); | |
}, $files)); | |
} | |
$files = lib_files(); | |
$classes = files_to_classes($files); | |
$inheritence_chain = array(); | |
foreach ($classes as $class) { | |
$inheritence_chain[$class] = get_inheritance_chain($class); | |
} | |
$rows = array(array('class', 'furthest_parent', 'depth')); | |
foreach ($inheritence_chain as $class => $parents) { | |
$rows[] = array($class, end($parents), count($parents)); | |
} | |
$csv = array_map(function($row) { return implode(',', $row);}, $rows); | |
file_put_contents(getenv('HOME') . '/d8_inheritence_depth.csv', implode("\n", $csv)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment