public static function findFiles($path, &$files, &$ignoredFiles)
{
$config = Config::factory();
$ignore_dirs = $config->ignore_dirs;
$dir = $config->project;
// Actually finding the files
$ignoreDirs = array();
foreach ($ignore_dirs as $ignore) {
if ($ignore[0] == '/') {
$d = $config->projects_root . '/projects/' . $dir . '/code' . $ignore;
if (!file_exists($d)) {
continue;
}
$ignoreDirs[] = $ignore . '.*';
} else {
$ignoreDirs[] = '.*' . $ignore . '.*';
}
}
if (empty($ignoreDirs)) {
$regex = '';
} else {
$regex = '#^(' . implode('|', $ignoreDirs) . ')#';
}
$php = new Phpexec();
$ignoredFiles = array();
$d = getcwd();
if (!file_exists($path)) {
display("No such file as " . $path . " when looking for files\n");
$files = array();
$ignoredFiles = array();
return;
}
chdir($path);
$files = rglob('.');
chdir($d);
$exts = $config->file_extensions;
foreach ($files as $id => &$file) {
$file = substr($file, 1);
$ext = pathinfo($file, PATHINFO_EXTENSION);
if (empty($ext)) {
// it's OK.
} elseif (!in_array($ext, $exts)) {
// selection of extensions
unset($files[$id]);
$ignoredFiles[$file] = "Ignored extension ({$ext})";
} elseif (!empty($regex) && preg_match($regex, $file)) {
// Matching the 'ignored dir' pattern
unset($files[$id]);
$ignoredFiles[$file] = 'Ignored dir';
} elseif ($php->countTokenFromFile($path . $file) < 2) {
unset($files[$id]);
$ignoredFiles[$file] = 'Not a PHP File';
}
}
}