Skip to content

Commit

Permalink
Create OrModifier.php
Browse files Browse the repository at this point in the history
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
  • Loading branch information
ghostwriter committed Aug 23, 2024
1 parent 4c29e33 commit 02cd898
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Selector/Modifier/OrModifier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php declare(strict_types=1);

namespace PHPat\Selector\Modifier;

use PHPat\Selector\SelectorInterface;
use PHPStan\Reflection\ClassReflection;

final class OrModifier implements SelectorInterface
{
/** @var array<SelectorInterface> */
private array $selectors;

public function __construct(SelectorInterface ...$selector)
{
$this->selectors = array_values($selector);
}

public function matches(ClassReflection $classReflection): bool
{
foreach ($this->selectors as $selector) {
if ($selector->matches($classReflection)) {
return true;
}
}

return false;
}

public function getName(): string
{
return implode(
':or:',
array_map(fn (SelectorInterface $selector) => $selector->getName(), $this->selectors),
);
}
}

0 comments on commit 02cd898

Please sign in to comment.