public function getFilter()
{
$rootDirectory = $this->rootDirectory;
$includePaths = $this->includePaths;
$excludePaths = $this->excludePaths;
return function (\SplFileInfo $file) use($rootDirectory, $includePaths, $excludePaths) {
if ($file->getExtension() !== 'php') {
return false;
}
$fullPath = $this->getFileFullPath($file);
$dir = dirname($fullPath);
// Do not touch files that not under rootDirectory
if (strpos($fullPath, $rootDirectory) !== 0) {
return false;
}
if (!empty($includePaths)) {
$found = false;
foreach ($includePaths as $includePattern) {
if (fnmatch($includePattern, $dir)) {
$found = true;
break;
}
}
if (!$found) {
return false;
}
}
foreach ($excludePaths as $excludePattern) {
if (fnmatch($excludePattern, $dir)) {
return false;
}
}
return true;
};
}