Skip to content

Commit

Permalink
Merge pull request #118 from VincentLanglet/fixIterator
Browse files Browse the repository at this point in the history
🐛 Fix iterator for file list
  • Loading branch information
VincentLanglet authored Feb 19, 2020
2 parents bd6a6e1 + 2301a42 commit ea7505a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
20 changes: 11 additions & 9 deletions TwigCS/src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ public function findFiles(): array
if (is_dir($path)) {
$flags = \RecursiveDirectoryIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS;
$directoryIterator = new \RecursiveDirectoryIterator($path, $flags);
} else {
$directoryIterator = new \RecursiveArrayIterator([new \SplFileInfo($path)]);
}

$filter = new TwigFileFilter($directoryIterator);
$iterator = new \RecursiveIteratorIterator($filter);

/** @var \SplFileInfo $file */
foreach ($iterator as $file) {
$filter = new TwigFileFilter($directoryIterator);
$iterator = new \RecursiveIteratorIterator($filter);

/** @var \SplFileInfo $file */
foreach ($iterator as $k => $file) {
$files[] = $file->getRealPath();
}
} elseif (is_file($path)) {
$file = new \SplFileInfo($path);
$files[] = $file->getRealPath();
} else {
throw new Exception(sprintf('Unknown path: "%s"', $path));
}
}

Expand Down
8 changes: 0 additions & 8 deletions TwigCS/src/Config/TwigFileFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
*/
class TwigFileFilter extends \RecursiveFilterIterator
{
/**
* @param \RecursiveIterator $iterator
*/
public function __construct(\RecursiveIterator $iterator)
{
parent::__construct($iterator);
}

/**
* @return bool
*/
Expand Down

0 comments on commit ea7505a

Please sign in to comment.