Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| RunGlobalMethodDefinition | |
100.00% |
8 / 8 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getBoundedContextId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMethod | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| provideActionDefinitions | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\Common\ActionDefinitions; |
| 3 | |
| 4 | use Apie\Core\BoundedContext\BoundedContext; |
| 5 | use Apie\Core\BoundedContext\BoundedContextId; |
| 6 | use Apie\Core\Context\ApieContext; |
| 7 | use Apie\Core\ContextConstants; |
| 8 | use ReflectionMethod; |
| 9 | |
| 10 | /** |
| 11 | * Action definition for modifying a single resource by id in a specific bounded context. |
| 12 | */ |
| 13 | final class RunGlobalMethodDefinition implements ActionDefinitionInterface |
| 14 | { |
| 15 | public function __construct( |
| 16 | private readonly ReflectionMethod $method, |
| 17 | private readonly BoundedContextId $boundedContextId |
| 18 | ) { |
| 19 | } |
| 20 | |
| 21 | public function getBoundedContextId(): BoundedContextId |
| 22 | { |
| 23 | return $this->boundedContextId; |
| 24 | } |
| 25 | |
| 26 | public function getMethod(): ReflectionMethod |
| 27 | { |
| 28 | return $this->method; |
| 29 | } |
| 30 | |
| 31 | |
| 32 | /** |
| 33 | * Business logic: |
| 34 | * - Check apie context with ContextConstants::GLOBAL_METHOD |
| 35 | */ |
| 36 | public static function provideActionDefinitions(BoundedContext $boundedContext, ApieContext $apieContext, bool $runtimeChecks = false): array |
| 37 | { |
| 38 | $actionDefinitions = []; |
| 39 | $globalActionContext = $apieContext->withContext(ContextConstants::GLOBAL_METHOD, true); |
| 40 | foreach ($boundedContext->actions->filterOnApieContext($globalActionContext, $runtimeChecks) as $action) { |
| 41 | $actionDefinitions[] = new RunGlobalMethodDefinition($action, $boundedContext->getId()); |
| 42 | } |
| 43 | |
| 44 | return $actionDefinitions; |
| 45 | } |
| 46 | } |