Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
BoundedContextPolicyProvider
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPolicyFor
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2namespace Apie\Core\Policies;
3
4use Apie\Core\Context\ApieContext;
5use Apie\Core\ContextConstants;
6
7class 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}