protected function getGraphsFromFiles(array $files, array $exclude, CFGParser $parser)
{
$excludeParts = [];
foreach ($exclude as $part) {
$excludeParts[] = preg_quote($part);
}
$part = implode('|', $excludeParts);
$excludeRegex = "(((\\.({$part})(\$|/))|((^|/)({$part})(\$|/))))";
$graphs = [];
foreach ($files as $file) {
if (is_file($file)) {
$local = [$file];
} elseif (is_dir($file)) {
$it = new \CallbackFilterIterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($file)), function (\SplFileInfo $file) use($excludeRegex) {
if (preg_match($excludeRegex, $file->getPathName())) {
return false;
}
return $file->isFile();
});
$local = [];
foreach ($it as $file) {
$local[] = $file->getPathName();
// since __toString would be too difficult...
}
} else {
throw new \RuntimeException("Error: {$file} is not a file or directory");
}
foreach ($local as $file) {
echo "Analyzing {$file}\n";
$graphs[$file] = $parser->parse(file_get_contents($file), $file);
}
}
return $graphs;
}