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

Multiple dirs class set #400

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\Rules\Rule;

return static function (Config $config): void {
$mvcClassSet = ClassSet::fromDir(__DIR__.'/mvc');
$mvcClassSet = ClassSet::fromDir(__DIR__.'/mvc', __DIR__.'/lib/my-lib/src');

$rules = [];

Expand Down
16 changes: 8 additions & 8 deletions src/ClassSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

class ClassSet implements \IteratorAggregate
{
/** @var string */
private $directory;
/** @var string[] */
private $directoryList;
AlessandroMinoccheri marked this conversation as resolved.
Show resolved Hide resolved

/** @var array */
private $exclude;

private function __construct(string $directory)
private function __construct(string ...$directoryList)
{
$this->directory = $directory;
$this->directoryList = $directoryList;
$this->exclude = [];
}

Expand All @@ -26,21 +26,21 @@ public function excludePath(string $pattern): self
return $this;
}

public static function fromDir(string $directory): self
public static function fromDir(string ...$directoryList): self
{
return new self($directory);
return new self(...$directoryList);
}

public function getDir(): string
{
return $this->directory;
return implode(', ', $this->directoryList);
}

public function getIterator(): \Traversable
{
$finder = (new Finder())
->files()
->in($this->directory)
->in($this->directoryList)
->name('*.php')
->sortByName()
->followLinks()
Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/ClassSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@

class ClassSetTest extends TestCase
{
public function test_can_exclude_files_or_directories_from_multiple_dir_class_set(): void
{
$path = $this->createMvcProjectStructure();

$set = ClassSet::fromDir($path.'/Controller', $path.'/Model')
->excludePath('Repository');

$expected = [
$path.'/Controller/CatalogController.php',
$path.'/Controller/Foo.php',
$path.'/Controller/ProductsController.php',
$path.'/Controller/UserController.php',
$path.'/Controller/YieldController.php',
$path.'/Model/Catalog.php',
$path.'/Model/Products.php',
$path.'/Model/User.php',
];
$actual = array_values(array_map(function ($item) {
/** @var \SplFileInfo $item */
return $item->getPathname();
}, iterator_to_array($set)));
self::assertEquals($expected, $actual);
}

public function test_can_exclude_files_or_directories(): void
{
$path = $this->createMvcProjectStructure();
Expand Down