Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| AnyApplies | |
0.00% |
0 / 5 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| applies | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Attributes; |
| 3 | |
| 4 | use Apie\Core\Context\ApieContext; |
| 5 | use Attribute; |
| 6 | |
| 7 | /** |
| 8 | * Add this attribute that succeeds if any succeed. Adding no arguments is failure. |
| 9 | */ |
| 10 | #[Attribute(Attribute::IS_REPEATABLE|Attribute::TARGET_CLASS|Attribute::TARGET_METHOD|Attribute::TARGET_PROPERTY|Attribute::TARGET_PARAMETER|Attribute::TARGET_CLASS_CONSTANT)] |
| 11 | final class AnyApplies implements ApieContextAttribute |
| 12 | { |
| 13 | /** @var ApieContextAttribute[] */ |
| 14 | private array $checks; |
| 15 | |
| 16 | public function __construct(ApieContextAttribute... $checks) |
| 17 | { |
| 18 | $this->checks = $checks; |
| 19 | } |
| 20 | |
| 21 | public function applies(ApieContext $context): bool |
| 22 | { |
| 23 | foreach ($this->checks as $check) { |
| 24 | if ($check->applies($context)) { |
| 25 | return true; |
| 26 | } |
| 27 | } |
| 28 | return false; |
| 29 | } |
| 30 | } |