Passed
Push — bump-dependencies ( b4f034...4ebfc0 )
by Mattia
12:55 queued 09:49
created

MatchedPatchOperation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 41
ccs 15
cts 15
cp 1
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 7 1
A getOpName() 0 3 1
A create() 0 3 1
A __construct() 0 4 1
A matchFor() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cypress\PatchManager;
6
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
9
class MatchedPatchOperation
10
{
11
    private array $operationData;
0 ignored issues
show
Coding Style introduced by
Private member variable "operationData" must contain a leading underscore
Loading history...
12
13
    private PatchOperationHandler $handler;
0 ignored issues
show
Coding Style introduced by
Private member variable "handler" must contain a leading underscore
Loading history...
14
15 7
    private function __construct(array $operationData, PatchOperationHandler $handler)
16
    {
17 7
        $this->operationData = $operationData;
18 7
        $this->handler = $handler;
19
    }
20
21 7
    public static function create(array $operationData, PatchOperationHandler $handler): MatchedPatchOperation
22
    {
23 7
        return new self($operationData, $handler);
24
    }
25
26
    /**
27
     * @param string $operationName
28
     * @return bool
29
     */
30 4
    public function matchFor(string $operationName): bool
31
    {
32 4
        return $operationName === $this->handler->getName();
33
    }
34
35
    /**
36
     * call handle on the handler
37
     */
38 3
    public function process(Patchable $patchable): void
39
    {
40 3
        $optionResolver = new OptionsResolver();
41 3
        $optionResolver->setRequired(['op']);
42 3
        $this->handler->configureOptions($optionResolver);
43 3
        $options = new OperationData($optionResolver->resolve($this->operationData));
44 3
        $this->handler->handle($patchable, $options);
45
    }
46
47 2
    public function getOpName(): string
48
    {
49 2
        return $this->handler->getName();
50
    }
51
}
52