Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
27.27% |
3 / 11 |
|
16.67% |
1 / 6 |
CRAP | |
0.00% |
0 / 1 |
| RemoveResourceAction | |
27.27% |
3 / 11 |
|
16.67% |
1 / 6 |
32.62 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| createForEntity | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
| getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUrl | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getVariant | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isSmallPage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\HtmlBuilders\ResourceActions; |
| 3 | |
| 4 | use Apie\Common\ActionDefinitions\ActionDefinitionInterface; |
| 5 | use Apie\Common\ActionDefinitions\RemoveResourceActionDefinition; |
| 6 | use Apie\Core\Context\ApieContext; |
| 7 | use Apie\Core\Entities\EntityInterface; |
| 8 | use Apie\HtmlBuilders\Configuration\CurrentConfiguration; |
| 9 | use Apie\HtmlBuilders\Enums\ActionDefinitionVariant; |
| 10 | use ReflectionClass; |
| 11 | |
| 12 | class RemoveResourceAction implements SingleResourceActionInterface |
| 13 | { |
| 14 | public function __construct( |
| 15 | private readonly EntityInterface $entity, |
| 16 | private readonly RemoveResourceActionDefinition $actionDefinition |
| 17 | ) { |
| 18 | } |
| 19 | |
| 20 | public static function createForEntity(EntityInterface $entity, ReflectionClass $entityClass, ActionDefinitionInterface $actionDefinition): ?self |
| 21 | { |
| 22 | if ($actionDefinition instanceof RemoveResourceActionDefinition) { |
| 23 | return $actionDefinition->getResourceName()->name === $entityClass->name ? new self($entity, $actionDefinition) : null; |
| 24 | } |
| 25 | |
| 26 | return null; |
| 27 | } |
| 28 | |
| 29 | public function getName(): string |
| 30 | { |
| 31 | return 'Delete'; |
| 32 | } |
| 33 | |
| 34 | public function getUrl(CurrentConfiguration $currentConfiguration): string |
| 35 | { |
| 36 | $id = $this->entity->getId()->toNative(); |
| 37 | return $currentConfiguration->getContextUrl( |
| 38 | 'resource/delete/' . $this->actionDefinition->getResourceName()->getShortName() . '/' . $id |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | public function getVariant(): ActionDefinitionVariant |
| 43 | { |
| 44 | return ActionDefinitionVariant::DANGER; |
| 45 | } |
| 46 | |
| 47 | public function isSmallPage(?ApieContext $apieContext = null): bool |
| 48 | { |
| 49 | return true; |
| 50 | } |
| 51 | } |