Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.86% |
13 / 14 |
|
85.71% |
6 / 7 |
CRAP | |
0.00% |
0 / 1 |
| RunMethodCallOnSingleResourceFormRouteDefinition | |
92.86% |
13 / 14 |
|
85.71% |
6 / 7 |
10.04 | |
0.00% |
0 / 1 |
| createFrom | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMethod | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUrl | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| getController | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAction | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getOperationId | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\Cms\RouteDefinitions; |
| 3 | |
| 4 | use Apie\Cms\Controllers\RunMethodCallOnSingleResourceFormController; |
| 5 | use Apie\Common\ActionDefinitions\ActionDefinitionInterface; |
| 6 | use Apie\Common\ActionDefinitions\RunResourceMethodDefinition; |
| 7 | use Apie\Common\Actions\RunItemMethodAction; |
| 8 | use Apie\Core\BoundedContext\BoundedContextId; |
| 9 | use Apie\Core\Enums\RequestMethod; |
| 10 | use Apie\Core\ValueObjects\UrlRouteDefinition; |
| 11 | use ReflectionClass; |
| 12 | use ReflectionMethod; |
| 13 | |
| 14 | class RunMethodCallOnSingleResourceFormRouteDefinition extends AbstractCmsRouteDefinition |
| 15 | { |
| 16 | public static function createFrom(ActionDefinitionInterface $actionDefinition): ?AbstractCmsRouteDefinition |
| 17 | { |
| 18 | if ($actionDefinition instanceof RunResourceMethodDefinition) { |
| 19 | return new self($actionDefinition->getResourceName(), $actionDefinition->getMethod(), $actionDefinition->getBoundedContextId()); |
| 20 | } |
| 21 | return null; |
| 22 | } |
| 23 | |
| 24 | public function __construct(ReflectionClass $class, ReflectionMethod $method, BoundedContextId $boundedContextId) |
| 25 | { |
| 26 | parent::__construct($class, $boundedContextId, $method); |
| 27 | } |
| 28 | |
| 29 | public function getMethod(): RequestMethod |
| 30 | { |
| 31 | return RequestMethod::GET; |
| 32 | } |
| 33 | |
| 34 | public function getUrl(): UrlRouteDefinition |
| 35 | { |
| 36 | $methodName = $this->method->getName(); |
| 37 | if ($methodName === '__invoke') { |
| 38 | return new UrlRouteDefinition('/resource/action/' . $this->class->getShortName() . '/{id}'); |
| 39 | } |
| 40 | return new UrlRouteDefinition('/resource/action/' . $this->class->getShortName() . '/{id}/' . $methodName); |
| 41 | } |
| 42 | |
| 43 | public function getController(): string |
| 44 | { |
| 45 | return RunMethodCallOnSingleResourceFormController::class; |
| 46 | } |
| 47 | |
| 48 | public function getAction(): string |
| 49 | { |
| 50 | return RunItemMethodAction::class; |
| 51 | } |
| 52 | |
| 53 | public function getOperationId(): string |
| 54 | { |
| 55 | $methodName = $this->method->getName(); |
| 56 | $suffix = $methodName === '__invoke' ? '' : ('-' . $methodName); |
| 57 | return 'form-call-resource-method-' . $this->class->getShortName() . $suffix; |
| 58 | } |
| 59 | } |