FiniteHandler   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 63
ccs 15
cts 17
cp 0.8824
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 3
A __construct() 0 3 1
A getName() 0 3 1
A canHandle() 0 3 1
A configureOptions() 0 6 1
1
<?php
2
3
namespace Cypress\PatchManager\Handler;
4
5
use Cypress\PatchManager\OperationData;
6
use Cypress\PatchManager\Patchable;
7
use Cypress\PatchManager\PatchOperationHandler;
8
use Finite\Factory\FactoryInterface;
9
use Symfony\Component\OptionsResolver\OptionsResolver;
10
11
class FiniteHandler implements PatchOperationHandler
12
{
13
    /**
14
     * @var FactoryInterface
15
     */
16
    private FactoryInterface $factoryInterface;
0 ignored issues
show
Coding Style introduced by
Private member variable "factoryInterface" must contain a leading underscore
Loading history...
17
18
    /**
19
     * @param FactoryInterface $factoryInterface
20
     */
21 5
    public function __construct(FactoryInterface $factoryInterface)
22
    {
23 5
        $this->factoryInterface = $factoryInterface;
24
    }
25
26
    /**
27
     * @param Patchable $subject
28
     * @param OperationData $operationData
29
     */
30 3
    public function handle(Patchable $subject, OperationData $operationData): void
31
    {
32 3
        $sm = $this->factoryInterface->get($subject);
33 3
        $transition = $operationData->get('transition')->get();
34 3
        if ($operationData->get('check')->get() && !$sm->can($transition)) {
35 1
            return;
36
        }
37 2
        $sm->apply($transition);
38
    }
39
40
    /**
41
     * the operation name
42
     *
43
     * @return string
44
     */
45 1
    public function getName(): string
46
    {
47 1
        return 'sm';
48
    }
49
50
    /**
51
     * use the OptionResolver instance to configure the required and optional fields that needs to be passed
52
     * with the request body. See http://symfony.com/doc/current/components/options_resolver.html to check all
53
     * possible options
54
     *
55
     * @param OptionsResolver $optionsResolver
56
     */
57 1
    public function configureOptions(OptionsResolver $optionsResolver): void
58
    {
59 1
        $optionsResolver
60 1
            ->setRequired(['transition'])
61 1
            ->setDefined(['check'])
62 1
            ->setDefaults(['check' => false]);
63
    }
64
65
    /**
66
     * whether the handler is able to handle the given subject
67
     *
68
     * @param Patchable $subject
69
     * @return bool
70
     */
71
    public function canHandle(Patchable $subject): bool
72
    {
73
        return true;
74
    }
75
}
76