matteosister /
patch-manager
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Cypress\PatchManager; |
||
| 4 | |||
| 5 | use Symfony\Component\OptionsResolver\OptionsResolver; |
||
| 6 | |||
| 7 | class MatchedPatchOperation |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var array |
||
| 11 | */ |
||
| 12 | private array $operationData; |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 13 | |||
| 14 | /** |
||
| 15 | * @var PatchOperationHandler |
||
| 16 | */ |
||
| 17 | private PatchOperationHandler $handler; |
||
|
0 ignored issues
–
show
|
|||
| 18 | |||
| 19 | /** |
||
| 20 | * @param array $operationData |
||
| 21 | * @param PatchOperationHandler $handler |
||
| 22 | */ |
||
| 23 | 7 | private function __construct(array $operationData, PatchOperationHandler $handler) |
|
| 24 | { |
||
| 25 | 7 | $this->operationData = $operationData; |
|
| 26 | 7 | $this->handler = $handler; |
|
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param array $operationData |
||
| 31 | * @param PatchOperationHandler $handler |
||
| 32 | * @return MatchedPatchOperation |
||
| 33 | */ |
||
| 34 | 7 | public static function create(array $operationData, PatchOperationHandler $handler): MatchedPatchOperation |
|
| 35 | { |
||
| 36 | 7 | return new self($operationData, $handler); |
|
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @param string $operationName |
||
| 41 | * @return bool |
||
| 42 | */ |
||
| 43 | 4 | public function matchFor(string $operationName): bool |
|
| 44 | { |
||
| 45 | 4 | return $operationName === $this->handler->getName(); |
|
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * call handle on the handler |
||
| 50 | * |
||
| 51 | * @param Patchable $patchable |
||
| 52 | */ |
||
| 53 | 3 | public function process(Patchable $patchable): void |
|
| 54 | { |
||
| 55 | 3 | $optionResolver = new OptionsResolver(); |
|
| 56 | 3 | $optionResolver->setRequired(['op']); |
|
| 57 | 3 | $this->handler->configureOptions($optionResolver); |
|
| 58 | 3 | $options = new OperationData($optionResolver->resolve($this->operationData)); |
|
| 59 | 3 | $this->handler->handle($patchable, $options); |
|
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @return string |
||
| 64 | */ |
||
| 65 | 2 | public function getOpName() |
|
| 66 | { |
||
| 67 | 2 | return $this->handler->getName(); |
|
| 68 | } |
||
| 69 | } |
||
| 70 |