workaround for missing/buggy path exclude in symfony finder class

@param array  $files
@param string $excludePath

@return array
199347
public function removeExcludedPath(array $files, $excludePath)
    {
        $result = $includedFiles = array();

        if (true === empty($excludePath)) {
            return $files;
        }

        foreach ($files as $filePath) {
            preg_match_all($this->coverFishHelper->getRegexPath($excludePath), $filePath, $result, PREG_SET_ORDER);
            if (true === empty($result)) {
                $includedFiles[] = $filePath;
            }
        }

        return $includedFiles;
    }
648718
protected function initPaths(array $exclude_dirs = [])
    {
        $apps_dir = $this->core->config->get('Core', 'dir.apps');
        $apps_url = $this->core->config->get('Core', 'url.apps');

        // Set path property which can be used on including additional app files like settings, routes, config etc
        $dir = $this->getDir();

        // Get directory path of app
        $scanned_directory = array_diff(scandir($dir), array(
            '..',
            '.'
        ));

        $this->paths = new Paths();

        $dir = $this->getDir();

        $string = new CamelCase('');

        foreach ($scanned_directory as $item) {

            if (is_dir($dir . '/' . $item) && !in_array($item, $exclude_dirs)) {

                $string->setString($item);
                $key = $string->uncamelize();

                $this->paths->add('dir.' . $key, $dir . '/' . $item);
                $this->paths->add('url.' . $key, $apps_url . '/' . $this->name . '/' . $item);
            }
        }

        // Add apps base dir and url to app config
        $this->paths->add('dir.app', $dir);
        $this->paths->add('url.app', $apps_url . '/' . $this->name);
    }
116890
def remove_excluded_files(files)
      return files if @exclude.empty?
      files.reject do |file|
        @exclude.any? { |exclude| File.fnmatch(exclude, file) }
      end
    end
580400
private function findTemplatesInDirectory($dir, $namespace = null, array $excludeDirs = [])
    {
        if (!is_dir($dir)) {
            return [];
        }

        $templates = [];
        foreach (Finder::create()->files()->followLinks()->in($dir)->exclude($excludeDirs) as $file) {
            $templates[] = (null !== $namespace ? '@'.$namespace.'/' : '').str_replace('\\', '/', $file->getRelativePathname());
        }

        return $templates;
    }
505626
private function excludeSubPaths(array $paths) : array
    {
        if (empty($paths)) {
            return $paths;
        }
        sort($paths);
        $uniquePaths = [$paths[0]];
        for ($i = 1, $count = count($paths); $i < $count; ++$i) {
            $lastUniquePath = end($uniquePaths);
            assert($lastUniquePath !== false);

            if (strpos($paths[$i], $lastUniquePath) === 0) {
                continue;
            }

            $uniquePaths[] = $paths[$i];
        }

        return $uniquePaths;
    }
435822
public function Index($ExtraPaths = NULL) {
      
      $FileMasks = array(
         sprintf(self::LOOKUP_CLASS_MASK, '*'),
         sprintf(self::LOOKUP_INTERFACE_MASK, '*')
      );
      
      $ExtraPathsRemove = NULL;
      if (!is_null($ExtraPaths)) {
         $ExtraPathsRemove = array();
         foreach ($ExtraPaths as $PathOpts) {
            $ExtraPath = GetValue('path', $PathOpts);
            if (array_key_exists($ExtraPath, $this->Paths)) continue;
            
            $ExtraPathsRemove[] = $ExtraPath;
            $ExtraOptions = $this->BuildOptions;
            $ExtraOptions['SplitTopic'] = GetValue('topic', $PathOpts);
            $this->AddPath($ExtraPath, $ExtraOptions);
         }
      }
      
      foreach ($this->Paths as $Path => $PathOptions) {

         $Recursive = GetValue('recursive', $PathOptions);
         $Files = $this->FindFiles($Path, $FileMasks, $Recursive);
         if ($Files === FALSE) continue;
         
         foreach ($Files as $File) {
            $SplitTopic = GetValue('topic', $PathOptions, self::TOPIC_DEFAULT);
            
            $ProvidedClass = $this->GetClassNameFromFile($File);
            if ($ProvidedClass) {
               $this->Map[$SplitTopic][$ProvidedClass] = $File;
               $this->MapInfo['dirty'] = TRUE;
            }
               
//            $ProvidesClasses = $this->Investigate($File);
//            if ($ProvidesClasses === FALSE) continue;
//            
//            foreach ($ProvidesClasses as $ProvidedClass) {
//               $ProvidedClass = strtolower($ProvidedClass);
//               $this->Map[$SplitTopic][$ProvidedClass] = $File;
//               $this->MapInfo['dirty'] = TRUE;
//            }
         }
      }
      
      // Save
      $this->Shutdown();
      
      if (!is_null($ExtraPathsRemove))
         foreach ($ExtraPathsRemove as $RemPath)
            unset($this->Paths[$RemPath]);
   }
491935
protected function setPathToUpdate(string $path, array $exclude)
    {
        $finder = (new Finder())->in($path)->exclude($exclude);

        $this->pathToUpdate = $finder;
    }
886575
public function locate($filePath)
    {
        $file = $filePath;
        if (!is_file($filePath))
        {
            throw new FileException(sprintf('Invalid file! File "%s" does not exist.',
                                            $filePath));
        }

        if (!is_readable($filePath))
        {
            throw new FileException(sprintf('Invalid file! File "%s" is not readable.',
                                            $filePath));
        }

        $pathInfo = pathinfo($filePath);
        if (!isset($pathInfo['extension'])
            || !in_array($pathInfo['extension'], $this->supportedExtensions)
        )
        {
            throw new FileException(sprintf('Invalid file extension! Supported file extensions: %s',
                implode(', ', $this->supportedExtensions)));
        }

        return realpath($file);
    }
1018778
private function getPreparedPaths(array $paths): array
    {
        $fullPaths = [];

        foreach ($paths as $name => $path) {
            if (\is_array($path)) {
                foreach ($path as $p) {
                    $fullPaths[] = \rtrim($this->vendorDir . \DIRECTORY_SEPARATOR . $name . \DIRECTORY_SEPARATOR . $p, '/');
                }
            } else {
                $fullPaths[] = \rtrim($this->vendorDir . \DIRECTORY_SEPARATOR . $name . \DIRECTORY_SEPARATOR . $path, '/');
            }
        }

        return $fullPaths;
    }
210486
private function applyExcludesAndIncludes(array $files, array $excludes = [], array $includes = []): array
    {
        if (!$excludes) {
            return $files;
        }

        foreach ($files as $key => $file) {
            if ($this->isMatch($file['relative_path'], $excludes)
                && !$this->isMatch(
                    $file['relative_path'],
                    $includes
                )) {
                unset($files[$key]);
            }
        }

        // Reindex to avoid confusion when comparing last index to count
        return array_values($files);
    }
504421
public static function getDirectoryFilenames($path, $subfolder=NULL, $fileList=array()) {
	
		// list of files to exclude
		$excludes = array('..', '.', '.DS_Store', 'thumbs.db', '.htaccess');
		
		try {
			
			// reads folders file and dirs as plain array
			$filenames = array_diff(scandir($path, 0), $excludes);
			
			// we look at each file/dir
			foreach ($filenames as $filename) {
	
				// relative file-path
				$file = $path . '/' . $filename;
		
				// it’s a directory, scan it
				if (is_dir($file)) {
	
					// recursive callback to scan new directory
					$fileList = self::getDirectoryFilenames($file, $subfolder . $filename . '/', $fileList);
						
				// it’s file, add it
				} else {
	
					$fileList[] = $subfolder . $filename;
						
				}
					
			}
	
		} catch (\Exception $e) {

			trigger_error($e->getMessage());
			return array();
			
		}
	
		return $fileList;
	
	}
955596
private function prepareFileList($path)
    {
        return Finder::create()
            ->files()
            ->in($path)
            ->name('*.php')
            ->notPath('/Tests/')
            ->notPath('/tests/')
            ->ignoreUnreadableDirs()
            ->ignoreDotFiles(true)
            ->ignoreVCS(true);
    }
1105402
protected function getFilenames(Collection $files)
    {
        $paths = $files->getFilenames();
        if (count($paths) < 1) {
            throw new FilesNotFoundException();
        }
        $this->log('Starting to process ' . count($paths) . ' files');

        return $paths;
    }
812908
public function createTraversable(array $paths, array $checkedExtensions, array $excludedPaths)
    {
        $directlyPassedFiles = array();
        $excludedPaths = $this->excludedPathCanonicalizer->canonicalize($paths, $excludedPaths);
        foreach ($paths as $path) {
            if (is_dir($path) && !$checkedExtensions) {
                throw new \DomainException('At least 1 extension must be specified to check a directory');
            } elseif (is_file($path)) {
                $directlyPassedFiles[] = realpath($path);
            }
        }

        $fileDirectoryIterator = new FileDirectoryListRecursiveIterator($paths);
        $extensionFilteringIterator = new ExtensionFilteringRecursiveIterator(
            $fileDirectoryIterator,
            $checkedExtensions,
            $directlyPassedFiles
        );
        $excludedPathFilteringIterator = new ExcludedPathFilteringRecursiveIterator(
            $extensionFilteringIterator,
            $excludedPaths
        );

        return new \RecursiveIteratorIterator(
            $excludedPathFilteringIterator,
            \RecursiveIteratorIterator::LEAVES_ONLY
        );
    }
383945
private function get_files_from_folders( $path ) {

		$items = $this::get_folder_contents( $path );

		foreach ( $items as $type => &$location ) {
			$location = $this::get_folder_contents( trailingslashit( $location ) );
			sort( $location );
		}

		return $items;
	}
1087615
public static function getIncludePath($filepath)
    {
        static $_include_path = null;

        if ($_path_array === null) {
            $_include_path = explode(PATH_SEPARATOR, get_include_path());
        }

        foreach ($_include_path as $_path) {
            if (file_exists($_path . DS . $filepath)) {
                return $_path . DS . $filepath;
            }
        }
        
        return false;
    }
378908
protected static function getFilesFromPath($path)
    {
        $files = [];
        $path = rtrim($path, '/') . DIRECTORY_SEPARATOR;

        if (false !== $items = scandir($path)) {
            foreach ($items as $item) {
                $file = $path . $item;
                if (is_file($file)) {
                    $extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
                    if (in_array($extension, [Packager::FILE_EXTENSION, Package::FILE_EXTENSION])) {
                        $files[] = $file;
                    }
                }
            }
        }

        return $files;
    }