@param string $file
@param array  $rsyncPatterns Array of match patterns in rsync exclude/include format
@see https://linux.die.net/man/1/rsync at "Include/Exclude Pattern Rules"

@return bool
330394
private function isMatch(string $file, array $rsyncPatterns): bool
    {
        $regexPatterns = [];
        foreach ($rsyncPatterns as $rsyncPattern) {
            $pattern = str_replace('\*', '*', preg_quote($rsyncPattern, '%'));
            $pattern = preg_replace('%([^*])$%', '$1(/|$)', $pattern);
            $pattern = preg_replace('%^([^*/])%', '(^|/)$1', $pattern);
            $pattern = preg_replace('%^/%', '^', $pattern);
            $pattern = str_replace('*', '.*', $pattern);
            $pattern = "%$pattern%";
            $regexPatterns[] = $pattern;
        }

        foreach ($regexPatterns as $pattern) {
            if (preg_match($pattern, $file)) {
                return true;
            }
        }

        return false;
    }
247880
public function exclude(array $patterns)
    {
        return $this->reject(function ($file) use ($patterns) {
            foreach ($patterns as $pattern) {
                if (Str::is($pattern, $file['name'])) return true;
            }

            return false;
        });
    }
157770
public static File[] listFiles(final File target, final List<Pattern> patterns, final boolean include) {
        if (patterns == null || patterns.isEmpty())
            return target.listFiles();

        return target.listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                for (Pattern pattern : patterns) {
                    Matcher matcher = pattern.matcher(name);
                    if (matcher.matches())
                        return include;
                }
                return !include;
            }

        });

    }
593804
public function rmFile($file)
    {

        if (!is_file($file)) {
            $this->errorMsg = "this is not a file";
            return false;
        }
        if (unlink($file)) {
            return true;
        } else {
            $this->errorMsg = "fail to remove the file!";
            return false;
        }
    }
411158
private function preparePattern(string ...$excludePatterns): ?string
    {
        if (count($excludePatterns) === 0) {
            return null;
        }

        return sprintf(
            '@^(%s)$@',
            implode(
                '|',
                array_map(
                    function (string $pattern): string {
                        return preg_quote(
                            str_replace('\\', '/', $pattern),
                            '@'
                        );
                    },
                    $excludePatterns
                )
            )
        );
    }
1348475
protected function validateCoversTagsAreRelative(File $file, array $tags)
    {
        foreach ($tags as $index => $value) {
            if (!empty($value) && substr($value, 0, 2) !== '::') {
                $file->addWarning(
                    'Covers tag should start with ::',
                    $index,
                    'CoversTagAbsolute',
                    [],
                    3
                );
            }
        }
    }
1309762
public static function grab_deps( $file ) {
		if ( ! file_exists( $file ) ) {
			return [];
		}
		// @see {wp-includes/functions.php}
		$fp = fopen( $file, 'r' );
		$file_header = fread( $fp, 8192 );
		fclose( $fp );
		// Make sure we catch CR-only line endings.
		$file_header = str_replace( "\r", "\n", $file_header );
		// Grab dependencies.
		$regexp = '#wpdeps=(.*)$#um';
		if ( ! preg_match_all( $regexp, $file_header, $matches ) ) {
			return [];
		} else {
			list( $match, $deps ) = $matches;
			$deps = [];
			foreach ( $matches[1] as $dep ) {
				foreach ( array_map( 'trim', explode( ',', $dep ) ) as $d ) {
					if ( $d ) {
						$deps[] = $d;
					}
				}
			}
			return $deps;
		}
	}
1185008
private function fileShouldBeIgnored(SplFileInfo $file): bool
    {
        foreach ($this->filesToIgnore as $fileToIgnore) {
            $regex = $this->patternToRegex($fileToIgnore);
            if (preg_match("#{$regex}#", $file->getPathName())) {
                return true;
            }
        }

        return false;
    }
597599
public function removeFromWhitelist(File $file)
    {
        if(!$this->whitelistContainsFile($file)){
            return false;
        }

        if(($key = array_search($this->filePath($file), $this->whiteList)) !== false) {
            unset($this->whiteList[$key]);
        }
        $this->writeWhitelist();
        return !$this->whitelistContainsFile($file);
    }
87616
public function ignoredByGlob($file)
    {
        $lfile = $file;
        if (strpos($lfile, './') === 0) {
            $lfile = substr($lfile, 2);
        }
        foreach ($this->ignoreFile as $line) {
            if (strpos($lfile, $line) === 0) {
                return true;
            }
        }
        return false;
    }
1241466
private function filterTracePaths($file)
	{
		$file = str_replace(DIRECTORY_SEPARATOR, '/', $file);
		$return = is_file($file);
		foreach ($this->skipPaths as $path) {
			if (!$return) {
				break;
			}
			$return = $return && strpos($file, '/' . trim($path, '/') . '/') === FALSE;
		}
		return $return;
	}
187703
protected function checkFilesArray($files)
    {
        if ($files != null && is_array($files) && !empty($files)) {
            foreach ($files as $file) {
                if ($file != null && is_array($file) && !empty($file)) {
                    return true;
                }
            }
        }
        return false;
    }
1251559
public static function verifyFilenameAgainstDenyPattern($filename) {
			// Filenames are not allowed to contain control characters
		if (preg_match('/[[:cntrl:]]/', $filename)) {
			return FALSE;
		}

		if (strcmp($filename, '') && strcmp($GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'], '')) {
			$result = preg_match('/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] . '/i', $filename);
			if ($result) {
				return FALSE;
			} // so if a matching filename is found, return FALSE;
		}
		return TRUE;
	}
1099187
protected function isExcluded(SplFileInfo $file, Collection $excludes)
    {
        return $excludes->contains(function ($exclude) use ($file) {
            return Str::startsWith($file->getPathname(), $exclude);
        });
    }
524825
protected function _include( $file )
	{
		if( !isset( $this->_includeCache[$file] ) ) {
			$this->_includeCache[$file] = include $file;
		}

		return $this->_includeCache[$file];
	}
878582
protected function hasSyntaxErrors($file) : bool
    {
        $process = new Processor();
        $result  = $process->run('php -l ' . escapeshellarg($file));

        return !$result->isSuccessful();
    }
992150
public function excludes($excludes)
    {
        if (is_string($excludes)) {
            $excludes = explode(',', $excludes);
        }

        // when autoload is enable, we need to merge user requested includes with the predefined includes.
        if ($this->autoload and $this->request->get($this->exclude_key)) {
            $excludes = array_merge($excludes, explode(',', $this->request->get($this->exclude_key)));
        }

        $this->manager->parseExcludes($excludes);

        return $this;
    }