Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| PatchSingleResourceRouteDefinition | |
100.00% |
8 / 8 |
|
100.00% |
6 / 6 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getOperationId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMethod | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUrl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAction | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createFrom | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\RestApi\RouteDefinitions; |
| 3 | |
| 4 | use Apie\Common\ActionDefinitions\ActionDefinitionInterface; |
| 5 | use Apie\Common\ActionDefinitions\ModifyResourceActionDefinition; |
| 6 | use Apie\Common\Actions\ModifyObjectAction; |
| 7 | use Apie\Core\BoundedContext\BoundedContextId; |
| 8 | use Apie\Core\ContextConstants; |
| 9 | use Apie\Core\Entities\EntityInterface; |
| 10 | use Apie\Core\Enums\RequestMethod; |
| 11 | use Apie\Core\ValueObjects\UrlRouteDefinition; |
| 12 | use ReflectionClass; |
| 13 | |
| 14 | /** |
| 15 | * Route definition for modifying a single resource. |
| 16 | */ |
| 17 | class PatchSingleResourceRouteDefinition extends AbstractRestApiRouteDefinition |
| 18 | { |
| 19 | /** |
| 20 | * @param ReflectionClass<EntityInterface> $className |
| 21 | */ |
| 22 | public function __construct(ReflectionClass $className, BoundedContextId $boundedContextId) |
| 23 | { |
| 24 | parent::__construct($className, $boundedContextId); |
| 25 | } |
| 26 | |
| 27 | public function getOperationId(): string |
| 28 | { |
| 29 | return 'patch-single-' . $this->class->getShortName(); |
| 30 | } |
| 31 | |
| 32 | public function getMethod(): RequestMethod |
| 33 | { |
| 34 | return RequestMethod::PATCH; |
| 35 | } |
| 36 | |
| 37 | public function getUrl(): UrlRouteDefinition |
| 38 | { |
| 39 | return new UrlRouteDefinition($this->class->getShortName() . '/{' . ContextConstants::RESOURCE_ID . '}'); |
| 40 | } |
| 41 | |
| 42 | public function getAction(): string |
| 43 | { |
| 44 | return ModifyObjectAction::class; |
| 45 | } |
| 46 | |
| 47 | public static function createFrom(ActionDefinitionInterface $actionDefinition): ?AbstractRestApiRouteDefinition |
| 48 | { |
| 49 | if ($actionDefinition instanceof ModifyResourceActionDefinition) { |
| 50 | return new self($actionDefinition->getResourceName(), $actionDefinition->getBoundedContextId()); |
| 51 | } |
| 52 | return null; |
| 53 | } |
| 54 | } |