From 5021e63397f44bd46797f8838b1806254f4feb4b Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 13 Aug 2019 15:53:16 +0200 Subject: [PATCH] Fix logic to include directories --- src/IterableCodeExtractor.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/IterableCodeExtractor.php b/src/IterableCodeExtractor.php index f2c286c8..11af44ec 100644 --- a/src/IterableCodeExtractor.php +++ b/src/IterableCodeExtractor.php @@ -159,9 +159,10 @@ protected static function containsMatchingChildren( SplFileInfo $dir, array $mat /** @var string $root_relative_path */ $root_relative_path = str_replace( static::$dir, '', $dir->getPathname() ); - $root_relative_path = ltrim( $root_relative_path, '/' ); foreach ( $matchers as $path_or_file ) { + $path_or_file = ltrim( $path_or_file, '/' ); + // If the matcher contains no wildcards and the path matches the start of the matcher. if ( '' !== $root_relative_path && @@ -205,19 +206,18 @@ public static function getFilesFromDirectory( $dir, array $include = [], array $ function ( $file, $key, $iterator ) use ( $include, $exclude, $extensions ) { /** @var RecursiveCallbackFilterIterator $iterator */ /** @var SplFileInfo $file */ - // If no $include is passed everything gets the weakest possible matching score. $inclusion_score = empty( $include ) ? 0.1 : static::calculateMatchScore( $file, $include ); $exclusion_score = static::calculateMatchScore( $file, $exclude ); // Always include directories that aren't excluded. - if ( 0 === $exclusion_score && $iterator->hasChildren() ) { + if ( $file->isDir() && 0 === $exclusion_score ) { return true; } - if ( 0 === $inclusion_score || $exclusion_score > $inclusion_score ) { + if ( $file->isDir() && ( 0 === $inclusion_score || $exclusion_score > $inclusion_score ) ) { // Always include directories that may have matching children even if they are excluded. - return $iterator->hasChildren() && static::containsMatchingChildren( $file, $include ); + return static::containsMatchingChildren( $file, $include ); } return ( $file->isFile() && in_array( $file->getExtension(), $extensions, true ) );