Find all php files by path.

@param string   $path
@param string[] $excludes

@return Finder|SplFileInfo[]
420717
public function findPHPFilesByPath(
        string $path,
        array $excludes
    ) {
        $finder = new Finder();

        if (file_exists($path) && !is_dir($path)) {
            $finder->append([0 => $path]);
        } else {
            $finder
                ->files()
                ->in($path)
                ->exclude($excludes)
                ->name('*.php');
        }

        return $finder;
    }
1178729
protected function findNewFiles(string $path) : array
    {
        $arrReturn = [];
        $arrFolders = scandir($path);
        $arrSkip = [
            '.',
            '..',
        ];
        
        foreach ($arrFolders as $file) {
            //No Folder Defaults
            if (in_array($file, $arrSkip)) {
                continue;
            }
            //Process Subfolders
            if (is_dir($path.$file)) {
                $arrSubFolderFiles = $this->findNewFiles($path.$file."/");
                $arrReturn = $this->addArrayToNewFiles($arrSubFolderFiles, $arrReturn);
                continue;
            }
            $arrReturn[] = $path.$file;
        }
        
        //Remove file from list if already processed
        foreach($arrReturn as $key => $file) {
            if (in_array($file, $this->knownUpdateFiles)) {
                unset($arrReturn[$key]);
            }
        }
        return $arrReturn;
    }
567176
private static function getPathFiles(array $path): array
    {
        // load external files
        $result = [];
        $pathFinder = Finder::findFiles('*')->in($path);
        foreach ($pathFinder as $file) {
            $result[$file->getRealPath()] = $file->getBaseName();
        }
        return $result;
    }
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);
    }
851009
public function directoryFiles($path)
  {
    $contents = [];

    // Scan directory
    $directoryFiles = scandir($path);

    foreach ($directoryFiles as $index => $filePath)  {

      // Ommit . and ..
      if ( ! in_array($filePath, ['.', '..']))  {

        // Check if this is a directory
        if (is_dir($path . DIRECTORY_SEPARATOR . $filePath)) {

          // Rescan and get files in this directory
          $contents = array_merge($contents, self::directoryFiles($path . DIRECTORY_SEPARATOR . $filePath));

        } else  {

          // Add file to contens array
          $contents[] = $path . DIRECTORY_SEPARATOR . $filePath;
        }
      }
    }

    return $contents;
  }
879734
public function findByPath(string $path)
    {
        return $this->first(function(ExtensionContract $extension) use($path) {
                    return $extension->getPath() === $path;
                });
    }
494865
protected function _excluded($path)
    {
        foreach ($this->_exclude as $exclude) {
            if (fnmatch($exclude, $path)) {
                return true;
            }
        }
        return false;
    }
195278
public function getPhpFiles(array $paths): FileCollection
    {
        $this->files = new FileCollection;
        foreach ($paths as $path) {
            $this->getPhpFilesFromPath($path);
        }

        return $this->files;
    }
1063239
public static function getFileList(string $path, array $exts = null) : array
    {
        $files = [];
        if (is_dir($path) && ($dh = opendir($path))) {
            while (($file = readdir($dh)) !== false) {
                if ($file === '.' || $file === '..' || $file === '.DS_Store') {
                    continue;
                } elseif (is_dir("{$path}/{$file}")) {
                    $files = array_merge($files, self::getFileList("{$path}/{$file}", $exts));
                } elseif (is_null($exts)) {
                    $files[] = "{$path}/{$file}";
                } elseif (in_array(pathinfo("{$path}/{$file}", PATHINFO_EXTENSION), $exts)) {
                    $files[] = "{$path}/{$file}";
                } else {
                    continue;
                }
            }
            closedir($dh);
        }
        return $files;
    }
958553
public function addToExclusions($path, $exclude)
    {
        collect($exclude)->each(function ($folder) use ($path) {
            $this->exclusions[] = $excluded = make_path([$path, $folder]);

            $this->showProgress("EXCLUDED: {$excluded}");
        });
    }
723311
public function listWorkingDir($path)
    {
        return Finder::create()
            ->files()
            ->name('*.php')
            ->in($this->workingDir.$path);
    }
1278746
public function getMappingFiles($path)
    {
        $files = $this->files->glob($path.'/*_*.php');

        if ($files === false) {
            return [];
        }

        $files = array_map(function ($file) {
            return str_replace('.php', '', basename($file));
        }, $files);

        return $files;
    }
992839
protected function getImageFiles($path)
    {
        $finder = Finder::create()->in($path)->sortByType()->depth(0);
        foreach (config('media.images_ext') as $file) {
            $finder->name('*' . $file);
        }

        return $finder;
    }
828155
public function getMigrationFiles($path)
    {
        $files = $this->files->glob($path .'/*_*.php');

        // Once we have the array of files in the directory we will just remove the
        // extension and take the basename of the file which is all we need when
        // finding the migrations that haven't been run against the databases.
        if ($files === false) return array();

        $files = array_map(function($file)
        {
            return str_replace('.php', '', basename($file));

        }, $files);

        // Once we have all of the formatted file names we will sort them and since
        // they all start with a timestamp this should give us the migrations in
        // the order they were actually created by the application developers.
        sort($files);

        return $files;
    }
196270
public function getFileSystemFiles( $relative_path, $only_dirs = false )
	{
		$files = array();

		// Extract directories:
		$iterator = new \DirectoryIterator( ROOT_PATH . "/$relative_path" );

		foreach ( $iterator as $file_info )
		{
			$file = $file_info->getFilename();

			// Exclude .svn, .cache and any other file starting with .
			if ( 0 !== strpos( $file, '.' ) )
			{
				if ( !$only_dirs || $file_info->isDir() )
				{
					$files[] = $file;
				}
			}
		}

		return $files;
	}
927374
protected function get_files( $path ) {
		$filtered_files = array();
		try {
			$files = new RecursiveIteratorIterator(
				new RecursiveDirectoryIterator(
					$path,
					RecursiveDirectoryIterator::SKIP_DOTS
				),
				RecursiveIteratorIterator::CHILD_FIRST
			);
			foreach ( $files as $file_info ) {
				$pathname = self::normalize_directory_separators( substr( $file_info->getPathname(), strlen( $path ) ) );
				if ( $file_info->isFile() && $this->filter_file( $pathname ) ) {
					$filtered_files[] = $pathname;
				}
			}
		} catch ( Exception $e ) {
			WP_CLI::error( $e->getMessage() );
		}

		return $filtered_files;
	}
292437
private function extractDirectories(string $path) : array
    {
        $remoteDirs = [];
        if (!empty($path)) {
            $remoteDirs = explode('/', $path);
            // fix empty first array element for absolute path
            if (substr($path, 0, 1) === '/') {
                $remoteDirs[0] = '/';
            }
            $remoteDirs = array_filter($remoteDirs);
        }
        return $remoteDirs;
    }