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
GetResourceListRouteDefinition
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\GetResourceListActionDefinition;
6use Apie\Common\Actions\GetListAction;
7use Apie\Core\BoundedContext\BoundedContextId;
8use Apie\Core\Entities\EntityInterface;
9use Apie\Core\Enums\RequestMethod;
10use Apie\Core\ValueObjects\UrlRouteDefinition;
11use ReflectionClass;
12
13/**
14 * Route definition for getting a list of resources.
15 */
16class GetResourceListRouteDefinition extends AbstractRestApiRouteDefinition
17{
18    /**
19     * @param ReflectionClass<EntityInterface> $className
20     */
21    public function __construct(ReflectionClass $className, BoundedContextId $boundedContextId)
22    {
23        parent::__construct($className, $boundedContextId);
24    }
25
26    public static function createFrom(ActionDefinitionInterface $actionDefinition): ?AbstractRestApiRouteDefinition
27    {
28        if ($actionDefinition instanceof GetResourceListActionDefinition) {
29            return new self($actionDefinition->getResourceName(), $actionDefinition->getBoundedContextId());
30        }
31
32        return null;
33    }
34
35    public function getOperationId(): string
36    {
37        return 'get-all-' . $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());
48    }
49
50    public function getAction(): string
51    {
52        return GetListAction::class;
53    }
54}