-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
- Loading branch information
1 parent
4c29e33
commit 02cd898
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
); | ||
} | ||
} |