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