Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
1 / 1
CreateResourceCommitRouteDefinition
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
7 / 7
9
100.00% covered (success)
100.00%
1 / 1
 createFrom
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 __construct
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
 getController
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
 getOperationId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\Cms\RouteDefinitions;
3
4use Apie\Cms\Controllers\FormCommitController;
5use Apie\Common\ActionDefinitions\ActionDefinitionInterface;
6use Apie\Common\ActionDefinitions\CreateResourceActionDefinition;
7use Apie\Common\ActionDefinitions\ReplaceResourceActionDefinition;
8use Apie\Common\Actions\CreateObjectAction;
9use Apie\Core\BoundedContext\BoundedContextId;
10use Apie\Core\Enums\RequestMethod;
11use Apie\Core\ValueObjects\UrlRouteDefinition;
12use ReflectionClass;
13
14class CreateResourceCommitRouteDefinition extends AbstractCmsRouteDefinition
15{
16    public static function createFrom(ActionDefinitionInterface $actionDefinition): ?AbstractCmsRouteDefinition
17    {
18        if ($actionDefinition instanceof CreateResourceActionDefinition) {
19            return new self($actionDefinition->getResourceName(), $actionDefinition->getBoundedContextId());
20        }
21        // TODO: should become PUT
22        if ($actionDefinition instanceof ReplaceResourceActionDefinition) {
23            return new self($actionDefinition->getResourceName(), $actionDefinition->getBoundedContextId());
24        }
25        return null;
26    }
27
28    public function __construct(ReflectionClass $class, BoundedContextId $boundedContextId)
29    {
30        parent::__construct($class, $boundedContextId);
31    }
32
33    public function getMethod(): RequestMethod
34    {
35        return RequestMethod::POST;
36    }
37
38    public function getUrl(): UrlRouteDefinition
39    {
40        return new UrlRouteDefinition('/resource/create/' . $this->class->getShortName());
41    }
42
43    public function getController(): string
44    {
45        return FormCommitController::class;
46    }
47
48    public function getAction(): string
49    {
50        return CreateObjectAction::class;
51    }
52
53    public function getOperationId(): string
54    {
55        return 'create-resource-commit-' . $this->class->getShortName();
56    }
57}