Skip to content

Commit

Permalink
Fix logic to include directories
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed Aug 13, 2019
1 parent ea60a20 commit 5021e63
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/IterableCodeExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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 ) );
Expand Down

0 comments on commit 5021e63

Please sign in to comment.