Skip to content
This repository was archived by the owner on Jul 12, 2020. It is now read-only.

Commit 74fbdb1

Browse files
committed
Allow multiple directories to back a Directory instance.
1 parent 3ce8c19 commit 74fbdb1

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

src/main/QafooLabs/Refactoring/Domain/Model/Directory.php

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,30 @@
1818
use RecursiveDirectoryIterator;
1919
use RecursiveIteratorIterator;
2020
use SplFileInfo;
21+
use AppendIterator;
2122

2223
/**
2324
* A directory in a project.
2425
*/
2526
class Directory
2627
{
2728
/**
28-
* @var string
29+
* @var array
2930
*/
30-
private $path;
31+
private $paths;
3132

3233
/**
3334
* @var string
3435
*/
3536
private $workingDirectory;
3637

37-
public function __construct($path, $workingDirectory)
38+
public function __construct($paths, $workingDirectory)
3839
{
39-
$this->path = $path;
40+
if (is_string($paths)) {
41+
$paths = array($paths);
42+
}
43+
44+
$this->paths = $paths;
4045
$this->workingDirectory = $workingDirectory;
4146
}
4247

@@ -47,22 +52,28 @@ public function findAllPhpFilesRecursivly()
4752
{
4853
$workingDirectory = $this->workingDirectory;
4954

50-
return
51-
new CallbackTransformIterator(
52-
new CallbackFilterIterator(
53-
new RecursiveIteratorIterator(
54-
new RecursiveDirectoryIterator($this->path),
55-
RecursiveIteratorIterator::LEAVES_ONLY
55+
$iterator = new AppendIterator;
56+
57+
foreach ($this->paths as $path) {
58+
$iterator->append(
59+
new CallbackTransformIterator(
60+
new CallbackFilterIterator(
61+
new RecursiveIteratorIterator(
62+
new RecursiveDirectoryIterator($path),
63+
RecursiveIteratorIterator::LEAVES_ONLY
64+
),
65+
function (SplFileInfo $file) {
66+
return substr($file->getFilename(), -4) === ".php";
67+
}
5668
),
57-
function (SplFileInfo $file) {
58-
return substr($file->getFilename(), -4) === ".php";
69+
function ($file) use ($workingDirectory) {
70+
return File::createFromPath($file->getPathname(), $workingDirectory);
5971
}
60-
),
61-
function ($file) use ($workingDirectory) {
62-
return File::createFromPath($file->getPathname(), $workingDirectory);
63-
}
64-
)
65-
;
72+
)
73+
);
74+
}
75+
76+
return $iterator;
6677
}
6778
}
6879

0 commit comments

Comments
 (0)