Skip to content

Commit 15ddd84

Browse files
committed
Result caching: minor optimization tweak [2]
Optimize use of the iterators: 1. Skip dot files at the `RecursiveDirectoryIterator` level by setting the `FilesystemIterator::SKIP_DOTS` flag and remove the code which was doing the same in the callback. Note: the other two flags are the default flags used by the `RecursiveDirectoryIterator` constructor, so are needed to maintain the existing behaviour. 2. No need for the `$file->getPathname()` function call. The `$key` already contains that information, as per the default flags. 3. No need for a file-system `is_dir()` call. If it's a directory, the iterator will have children.
1 parent 5ee7531 commit 15ddd84

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/Util/Cache.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,27 +95,25 @@ public static function load(Ruleset $ruleset, Config $config)
9595
// hash. This ensures that core PHPCS changes will also invalidate the cache.
9696
// Note that we ignore sniffs here, and any files that don't affect
9797
// the outcome of the run.
98-
$di = new \RecursiveDirectoryIterator($installDir);
98+
$di = new \RecursiveDirectoryIterator(
99+
$installDir,
100+
(\FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS)
101+
);
99102
$filter = new \RecursiveCallbackFilterIterator(
100103
$di,
101104
function ($file, $key, $iterator) {
102-
// Skip hidden files.
103-
$filename = $file->getFilename();
104-
if (substr($filename, 0, 1) === '.') {
105-
return false;
106-
}
107-
108105
// Skip non-php files.
106+
$filename = $file->getFilename();
109107
if ($file->isFile() === true && substr($filename, -4) !== '.php') {
110108
return false;
111109
}
112110

113-
$filePath = Common::realpath($file->getPathname());
111+
$filePath = Common::realpath($key);
114112
if ($filePath === false) {
115113
return false;
116114
}
117115

118-
if (is_dir($filePath) === true
116+
if ($iterator->hasChildren() === true
119117
&& ($filename === 'Standards'
120118
|| $filename === 'Exceptions'
121119
|| $filename === 'Reports'

0 commit comments

Comments
 (0)