Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.00% |
4 / 5 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| BoundedContextPolicyProvider | |
80.00% |
4 / 5 |
|
50.00% |
1 / 2 |
3.07 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPolicyFor | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Policies; |
| 3 | |
| 4 | use Apie\Core\Context\ApieContext; |
| 5 | use Apie\Core\ContextConstants; |
| 6 | |
| 7 | class BoundedContextPolicyProvider implements PolicyProviderInterface |
| 8 | { |
| 9 | public function __construct( |
| 10 | private readonly PolicyProviderHashmap $policiesByBoundedContext, |
| 11 | private readonly FallbackPolicy $fallbackPolicy, |
| 12 | ) { |
| 13 | } |
| 14 | |
| 15 | public function getPolicyFor(ApieContext $apieContext, string $action): object |
| 16 | { |
| 17 | $boundedContext = $apieContext->getContext(ContextConstants::BOUNDED_CONTEXT_ID, false); |
| 18 | if ($boundedContext === null) { |
| 19 | return $this->fallbackPolicy; |
| 20 | } |
| 21 | |
| 22 | // @phpstan-ignore nullCoalesce.expr |
| 23 | return $this->policiesByBoundedContext[$boundedContext]->getPolicyFor($apieContext, $action) ?? $this->fallbackPolicy; |
| 24 | } |
| 25 | } |