protected static function calculateMatchScore( SplFileInfo $file, array $matchers = [] ) {
		if ( empty( $matchers ) ) {
			return 0;
		}

		if ( in_array( $file->getBasename(), $matchers, true ) ) {
			return 10;
		}

		// Check for more complex paths, e.g. /some/sub/folder.
		$root_relative_path = str_replace( static::$dir, '', $file->getPathname() );

		foreach ( $matchers as $path_or_file ) {
			$pattern = preg_quote( str_replace( '*', '__wildcard__', $path_or_file ), '/' );
			$pattern = '(^|/)' . str_replace( '__wildcard__', '(.+)', $pattern );

			// Base score is the amount of nested directories, discounting wildcards.
			$base_score = count(
				array_filter(
					explode( '/', $path_or_file ),
					function ( $component ) {
						return '*' !== $component;
					}
				)
			);
			if ( 0 === $base_score ) {
				// If the matcher is simply * it gets a score above the implicit score but below 1.
				$base_score = 0.2;
			}

			// If the matcher contains no wildcards and matches the end of the path.
			if (
				false === strpos( $path_or_file, '*' ) &&
				false !== mb_ereg( $pattern . '$', $root_relative_path )
			) {
				return $base_score * 10;
			}

			// If the matcher matches the end of the path or a full directory contained.
			if ( false !== mb_ereg( $pattern . '(/|$)', $root_relative_path ) ) {
				return $base_score;
			}
		}

		return 0;
	}
protected static function calculateMatchScore( SplFileInfo $file, array $matchers = [] ) {
		if ( empty( $matchers ) ) {
			return 0;
		}

		if ( in_array( $file->getBasename(), $matchers, true ) ) {
			return 10;
		}

		// Check for more complex paths, e.g. /some/sub/folder.
		$root_relative_path = str_replace( static::$dir, '', $file->getPathname() );

		foreach ( $matchers as $path_or_file ) {
			$pattern = preg_quote( str_replace( '*', '__wildcard__', $path_or_file ), '/' );
			$pattern = '(^|/)' . str_replace( '__wildcard__', '(.+)', $pattern );

			// Base score is the amount of nested directories, discounting wildcards.
			$base_score = count(
				array_filter(
					explode( '/', $path_or_file ),
					function ( $component ) {
						return '*' !== $component;
					}
				)
			);
			if ( 0 === $base_score ) {
				// If the matcher is simply * it gets a score above the implicit score but below 1.
				$base_score = 0.2;
			}

			// If the matcher contains no wildcards and matches the end of the path.
			if (
				false === strpos( $path_or_file, '*' ) &&
				false !== mb_ereg( $pattern . '$', $root_relative_path )
			) {
				return $base_score * 10;
			}

			// If the matcher matches the end of the path or a full directory contained.
			if ( false !== mb_ereg( $pattern . '(/|$)', $root_relative_path ) ) {
				return $base_score;
			}
		}

		return 0;
	}
protected static function calculateMatchScore ( SplFileInfo $ file , array $ matchers = [ ] ) { if ( empty ( $ matchers ) ) { return 0 ; } if ( in_array ( $ file -> getBasename ( ) , $ matchers , true ) ) { return 10 ; } // Check for more complex paths, e.g. /some/sub/folder. $ root_relative_path = str_replace ( static :: $ dir , '' , $ file -> getPathname ( ) ) ; foreach ( $ matchers as $ path_or_file ) { $ pattern = preg_quote ( str_replace ( '*' , '__wildcard__' , $ path_or_file ) , '/' ) ; $ pattern = '(^|/)' . str_replace ( '__wildcard__' , '(.+)' , $ pattern ) ; // Base score is the amount of nested directories, discounting wildcards. $ base_score = count ( array_filter ( explode ( '/' , $ path_or_file ) , function ( $ component ) { return '*' !== $ component ; } ) ) ; if ( 0 === $ base_score ) { // If the matcher is simply * it gets a score above the implicit score but below 1. $ base_score = 0.2 ; } // If the matcher contains no wildcards and matches the end of the path. if ( false === strpos ( $ path_or_file , '*' ) && false !== mb_ereg ( $ pattern . '$' , $ root_relative_path ) ) { return $ base_score * 10 ; } // If the matcher matches the end of the path or a full directory contained. if ( false !== mb_ereg ( $ pattern . '(/|$)' , $ root_relative_path ) ) { return $ base_score ; } } return 0 ; }
Determines whether a file is valid based on given matchers.

@param SplFileInfo $file     File or directory.
@param array       $matchers List of files and directories to match.
@return int How strongly the file is matched.
Determines whether a file is valid based on given matchers .