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
GetSingleResourceRouteDefinition
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
 createFrom
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 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
1<?php
2namespace Apie\RestApi\RouteDefinitions;
3
4use Apie\Common\ActionDefinitions\ActionDefinitionInterface;
5use Apie\Common\ActionDefinitions\GetResourceActionDefinition;
6use Apie\Common\Actions\GetItemAction;
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 getting a single resource.
16 */
17class GetSingleResourceRouteDefinition 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 static function createFrom(ActionDefinitionInterface $actionDefinition): ?AbstractRestApiRouteDefinition
28    {
29        if ($actionDefinition instanceof GetResourceActionDefinition) {
30            return new self($actionDefinition->getResourceName(), $actionDefinition->getBoundedContextId());
31        }
32        return null;
33    }
34
35    public function getOperationId(): string
36    {
37        return 'get-single-' . $this->class->getShortName();
38    }
39
40    public function getMethod(): RequestMethod
41    {
42        return RequestMethod::GET;
43    }
44
45    public function getUrl(): UrlRouteDefinition
46    {
47        return new UrlRouteDefinition($this->class->getShortName() . '/{' . ContextConstants::RESOURCE_ID . '}');
48    }
49
50    public function getAction(): string
51    {
52        return GetItemAction::class;
53    }
54}