| Total Complexity | 7 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 88.24% |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | class FiniteHandler implements PatchOperationHandler |
||
| 14 | { |
||
| 15 | private FactoryInterface $factoryInterface; |
||
|
|
|||
| 16 | |||
| 17 | 5 | public function __construct(FactoryInterface $factoryInterface) |
|
| 18 | { |
||
| 19 | 5 | $this->factoryInterface = $factoryInterface; |
|
| 20 | } |
||
| 21 | |||
| 22 | 3 | public function handle(Patchable $subject, OperationData $operationData): void |
|
| 23 | { |
||
| 24 | 3 | $sm = $this->factoryInterface->get($subject); |
|
| 25 | 3 | $transition = $operationData->get('transition')->get(); |
|
| 26 | 3 | if ($operationData->get('check')->get() && !$sm->can($transition)) { |
|
| 27 | 1 | return; |
|
| 28 | } |
||
| 29 | 2 | $sm->apply($transition); |
|
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * the operation name |
||
| 34 | */ |
||
| 35 | 1 | public function getName(): string |
|
| 36 | { |
||
| 37 | 1 | return 'sm'; |
|
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * use the OptionResolver instance to configure the required and optional fields that needs to be passed |
||
| 42 | * with the request body. See http://symfony.com/doc/current/components/options_resolver.html to check all |
||
| 43 | * possible options |
||
| 44 | */ |
||
| 45 | 1 | public function configureOptions(OptionsResolver $optionsResolver): void |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * whether the handler is able to handle the given subject |
||
| 55 | */ |
||
| 56 | public function canHandle(Patchable $subject): bool |
||
| 61 |