Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
PutResourceRouteDefinition
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
5 / 5
6
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
 getOperationId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUrl
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMethod
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createFrom
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2namespace Apie\RestApi\RouteDefinitions;
3
4use Apie\Common\ActionDefinitions\ActionDefinitionInterface;
5use Apie\Common\ActionDefinitions\ReplaceResourceActionDefinition;
6use Apie\Core\BoundedContext\BoundedContextId;
7use Apie\Core\ContextConstants;
8use Apie\Core\Entities\EntityInterface;
9use Apie\Core\Enums\RequestMethod;
10use Apie\Core\ValueObjects\UrlRouteDefinition;
11use ReflectionClass;
12
13/**
14 * PUT route for creating or replacing a resource with a client-provided identifier.
15 */
16final 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}