Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| PutResourceRouteDefinition | |
100.00% |
7 / 7 |
|
100.00% |
5 / 5 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getOperationId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUrl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMethod | |
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\ReplaceResourceActionDefinition; |
| 6 | use Apie\Core\BoundedContext\BoundedContextId; |
| 7 | use Apie\Core\ContextConstants; |
| 8 | use Apie\Core\Entities\EntityInterface; |
| 9 | use Apie\Core\Enums\RequestMethod; |
| 10 | use Apie\Core\ValueObjects\UrlRouteDefinition; |
| 11 | use ReflectionClass; |
| 12 | |
| 13 | /** |
| 14 | * PUT route for creating or replacing a resource with a client-provided identifier. |
| 15 | */ |
| 16 | final class PutResourceRouteDefinition extends CreateResourceRouteDefinition |
| 17 | { |
| 18 | /** |
| 19 | * @param ReflectionClass<covariant EntityInterface> $className |
| 20 | */ |
| 21 | public function __construct(ReflectionClass $className, BoundedContextId $boundedContextId) |
| 22 | { |
| 23 | parent::__construct($className, $boundedContextId, true); |
| 24 | } |
| 25 | |
| 26 | public function getOperationId(): string |
| 27 | { |
| 28 | return 'replace-' . $this->class->getShortName(); |
| 29 | } |
| 30 | |
| 31 | public function getUrl(): UrlRouteDefinition |
| 32 | { |
| 33 | return new UrlRouteDefinition($this->class->getShortName() . '/{' . ContextConstants::RESOURCE_ID . '}'); |
| 34 | } |
| 35 | |
| 36 | public function getMethod(): RequestMethod |
| 37 | { |
| 38 | return RequestMethod::PUT; |
| 39 | } |
| 40 | |
| 41 | public static function createFrom(ActionDefinitionInterface $actionDefinition): ?AbstractRestApiRouteDefinition |
| 42 | { |
| 43 | if ($actionDefinition instanceof ReplaceResourceActionDefinition) { |
| 44 | return new self($actionDefinition->getResourceName(), $actionDefinition->getBoundedContextId()); |
| 45 | } |
| 46 | return null; |
| 47 | } |
| 48 | } |