Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| AbstractRestApiRouteDefinition | |
100.00% |
17 / 17 |
|
100.00% |
7 / 7 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getInputType | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getOutputType | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getPossibleActionResponseStatuses | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getController | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getDescription | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getTags | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getRouteAttributes | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Common\RouteDefinitions; |
| 3 | |
| 4 | use Apie\Common\Interfaces\RestApiRouteDefinition; |
| 5 | use Apie\Core\Actions\ActionResponseStatusList; |
| 6 | use Apie\Core\BoundedContext\BoundedContextId; |
| 7 | use Apie\Core\ContextConstants; |
| 8 | use Apie\Core\Dto\ListOf; |
| 9 | use Apie\Core\Lists\StringList; |
| 10 | use ReflectionClass; |
| 11 | use ReflectionMethod; |
| 12 | use ReflectionType; |
| 13 | |
| 14 | abstract class AbstractRestApiRouteDefinition implements RestApiRouteDefinition |
| 15 | { |
| 16 | /** |
| 17 | * @param ReflectionClass<object> $class |
| 18 | */ |
| 19 | public function __construct( |
| 20 | protected readonly ReflectionClass $class, |
| 21 | protected readonly ?BoundedContextId $boundedContextId = null, |
| 22 | protected readonly ?ReflectionMethod $method = null |
| 23 | ) { |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @return ReflectionClass<object>|ReflectionMethod|ReflectionType |
| 28 | */ |
| 29 | final public function getInputType(): ReflectionClass|ReflectionMethod|ReflectionType |
| 30 | { |
| 31 | $actionClass = $this->getAction(); |
| 32 | return $actionClass::getInputType($this->class, $this->method); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @return ReflectionClass<object>|ReflectionMethod|ReflectionType|ListOf |
| 37 | */ |
| 38 | final public function getOutputType(): ReflectionClass|ReflectionMethod|ReflectionType|ListOf |
| 39 | { |
| 40 | $actionClass = $this->getAction(); |
| 41 | return $actionClass::getOutputType($this->class, $this->method); |
| 42 | } |
| 43 | |
| 44 | final public function getPossibleActionResponseStatuses(): ActionResponseStatusList |
| 45 | { |
| 46 | $actionClass = $this->getAction(); |
| 47 | return $actionClass::getPossibleActionResponseStatuses($this->method); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @return class-string<object> |
| 52 | */ |
| 53 | abstract public function getController(): string; |
| 54 | |
| 55 | final public function getDescription(): string |
| 56 | { |
| 57 | $actionClass = $this->getAction(); |
| 58 | return $actionClass::getDescription($this->class, $this->method); |
| 59 | } |
| 60 | |
| 61 | final public function getTags(): StringList |
| 62 | { |
| 63 | $actionClass = $this->getAction(); |
| 64 | return $actionClass::getTags($this->class, $this->method); |
| 65 | } |
| 66 | |
| 67 | final public function getRouteAttributes(): array |
| 68 | { |
| 69 | $actionClass = $this->getAction(); |
| 70 | $attributes = $actionClass::getRouteAttributes($this->class, $this->method); |
| 71 | $attributes[ContextConstants::APIE_ACTION] = $this->getAction(); |
| 72 | $attributes[ContextConstants::OPERATION_ID] = $this->getOperationId(); |
| 73 | $attributes[ContextConstants::BOUNDED_CONTEXT_ID] = $this->boundedContextId->toNative(); |
| 74 | return $attributes; |
| 75 | } |
| 76 | } |