Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| RunGlobalMethodCommitRouteDefinition | |
100.00% |
17 / 17 |
|
100.00% |
7 / 7 |
11 | |
100.00% |
1 / 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 | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| 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\FormCommitController; |
| 5 | use Apie\Common\ActionDefinitions\ActionDefinitionInterface; |
| 6 | use Apie\Common\ActionDefinitions\RunGlobalMethodDefinition; |
| 7 | use Apie\Common\Actions\RunAction; |
| 8 | use Apie\Common\Concerns\ReadsRouteAttribute; |
| 9 | use Apie\Core\Attributes\Route; |
| 10 | use Apie\Core\BoundedContext\BoundedContextId; |
| 11 | use Apie\Core\Enums\RequestMethod; |
| 12 | use Apie\Core\ValueObjects\UrlRouteDefinition; |
| 13 | use ReflectionMethod; |
| 14 | |
| 15 | class RunGlobalMethodCommitRouteDefinition extends AbstractCmsRouteDefinition |
| 16 | { |
| 17 | use ReadsRouteAttribute; |
| 18 | |
| 19 | private const CURRENT_TARGET = Route::CMS; |
| 20 | |
| 21 | public static function createFrom(ActionDefinitionInterface $actionDefinition): ?AbstractCmsRouteDefinition |
| 22 | { |
| 23 | if ($actionDefinition instanceof RunGlobalMethodDefinition) { |
| 24 | return new self($actionDefinition->getMethod(), $actionDefinition->getBoundedContextId()); |
| 25 | } |
| 26 | return null; |
| 27 | } |
| 28 | |
| 29 | public function __construct(ReflectionMethod $method, BoundedContextId $boundedContextId) |
| 30 | { |
| 31 | parent::__construct($method->getDeclaringClass(), $boundedContextId, $method); |
| 32 | } |
| 33 | |
| 34 | public function getMethod(): RequestMethod |
| 35 | { |
| 36 | return RequestMethod::POST; |
| 37 | } |
| 38 | |
| 39 | public function getUrl(): UrlRouteDefinition |
| 40 | { |
| 41 | $route = $this->getRouteAttribute(); |
| 42 | if ($route) { |
| 43 | return new UrlRouteDefinition($route->routeDefinition); |
| 44 | } |
| 45 | $methodName = $this->method->getName(); |
| 46 | if ($methodName === '__invoke') { |
| 47 | return new UrlRouteDefinition('action/' . $this->method->getDeclaringClass()->getShortName()); |
| 48 | } |
| 49 | return new UrlRouteDefinition('action/' . $this->method->getDeclaringClass()->getShortName() . '/' . $methodName); |
| 50 | } |
| 51 | |
| 52 | public function getController(): string |
| 53 | { |
| 54 | return FormCommitController::class; |
| 55 | } |
| 56 | |
| 57 | public function getAction(): string |
| 58 | { |
| 59 | return RunAction::class; |
| 60 | } |
| 61 | |
| 62 | public function getOperationId(): string |
| 63 | { |
| 64 | $methodName = $this->method->getName(); |
| 65 | $suffix = $methodName === '__invoke' ? '' : ('-' . $methodName); |
| 66 | return 'call-method-commit-' . $this->method->getDeclaringClass()->getShortName() . $suffix; |
| 67 | } |
| 68 | } |