-
Notifications
You must be signed in to change notification settings - Fork 42
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 358508e
Showing
1 changed file
with
38 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,38 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace PHPat\Selector\Modifier; | ||
|
||
use PHPat\Selector\SelectorInterface; | ||
use PHPStan\Reflection\ClassReflection; | ||
|
||
final class XorModifier implements SelectorInterface | ||
{ | ||
/** @var array<SelectorInterface> */ | ||
private array $selectors; | ||
|
||
public function __construct(SelectorInterface ...$selector) | ||
{ | ||
$this->selectors = array_values($selector); | ||
} | ||
|
||
public function matches(ClassReflection $classReflection): bool | ||
{ | ||
$matches = 0; | ||
|
||
foreach ($this->selectors as $selector) { | ||
if ($selector->matches($classReflection)) { | ||
++$matches; | ||
} | ||
} | ||
|
||
return $matches === 1; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return implode( | ||
':xor:', | ||
array_map(static fn (SelectorInterface $selector) => $selector->getName(), $this->selectors), | ||
); | ||
} | ||
} |