Passed
Push — bump-dependencies ( 3eb1c7...418b80 )
by Mattia
15:26 queued 12:02
created

MatchedPatchOperation::matchFor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 4
    public function matchFor(string $operationName): bool
27
    {
28 4
        return $operationName === $this->handler->getName();
29
    }
30
31
    /**
32
     * call handle on the handler
33
     */
34 3
    public function process(Patchable $patchable): void
35
    {
36 3
        $optionResolver = new OptionsResolver();
37 3
        $optionResolver->setRequired(['op']);
38 3
        $this->handler->configureOptions($optionResolver);
39 3
        $options = new OperationData($optionResolver->resolve($this->operationData));
40 3
        $this->handler->handle($patchable, $options);
41
    }
42
43 2
    public function getOpName(): string
44
    {
45 2
        return $this->handler->getName();
46
    }
47
}
48