Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #74 - Reduce indentation levels in FileManager #75

Merged
merged 1 commit into from
Aug 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions src/Managers/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class FileManager
*/
private $config;

/**
* Collection of File objects.
* @var FileCollection;
*/
private $files;

/**
* FileManager constructor.
* @param Config $config Configuration Settings.
Expand All @@ -28,30 +34,40 @@ public function __construct(Config $config)

/**
* Recursively finds all files with the .php extension in the provided
* $path and returns list as array.
* $paths and returns list as array.
* @param array $paths Paths in which to look for .php files.
* @return FileCollection
*/
public function getPhpFiles(array $paths): FileCollection
{
$files = new FileCollection;
$this->files = new FileCollection;
foreach ($paths as $path) {
$directoryIterator = new RecursiveDirectoryIterator($path);
foreach (new RecursiveIteratorIterator($directoryIterator) as $file) {
if ($file->getExtension() !== 'php') {
continue;
}
$this->getPhpFilesFromPath($path);
}

if ($this->fileShouldBeIgnored($file)) {
continue;
}
return $this->files;
}

/**
* Recursively finds all files with the .php extension in the provided
* $path adds them to $this->files.
* @param string $path Path in which to look for .php files.
* @return void
*/
private function getPhpFilesFromPath(string $path)
{
$directoryIterator = new RecursiveDirectoryIterator($path);
foreach (new RecursiveIteratorIterator($directoryIterator) as $file) {
if ($file->getExtension() !== 'php') {
continue;
}

$files->push(new File(['displayPath' => $file->getPathName(), 'fullPath' => $file->getRealPath()]));
if ($this->fileShouldBeIgnored($file)) {
continue;
}
}

return $files;
$this->files->push(new File(['displayPath' => $file->getPathName(), 'fullPath' => $file->getRealPath()]));
}
}

/**
Expand Down