Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
RemoveSingleResourceRouteDefinition
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
6 / 6
7
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
 getMethod
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
 getAction
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\RemoveResourceActionDefinition;
6use Apie\Common\Actions\RemoveObjectAction;
7use Apie\Core\BoundedContext\BoundedContextId;
8use Apie\Core\ContextConstants;
9use Apie\Core\Entities\EntityInterface;
10use Apie\Core\Enums\RequestMethod;
11use Apie\Core\ValueObjects\UrlRouteDefinition;
12use ReflectionClass;
13
14/**
15 * Route definition for removing a single resource.
16 */
17class RemoveSingleResourceRouteDefinition 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 'remove-single-' . $this->class->getShortName();
30    }
31
32    public function getMethod(): RequestMethod
33    {
34        return RequestMethod::DELETE;
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 RemoveObjectAction::class;
45    }
46
47    public static function createFrom(ActionDefinitionInterface $actionDefinition): ?AbstractRestApiRouteDefinition
48    {
49        if ($actionDefinition instanceof RemoveResourceActionDefinition) {
50            return new self($actionDefinition->getResourceName(), $actionDefinition->getBoundedContextId());
51        }
52        return null;
53    }
54}