|
1 | 1 | <?php
|
2 | 2 |
|
3 |
| -namespace PatchManager; |
| 3 | +namespace Cypress\PatchManager; |
4 | 4 |
|
5 |
| -use PatchManager\Request\Operations; |
| 5 | +use Cypress\PatchManager\Request\Operations; |
6 | 6 | use PhpCollection\Sequence;
|
| 7 | +use PhpOption\Option; |
7 | 8 |
|
8 | 9 | /**
|
9 | 10 | * Match the correct handlers based on actual operations
|
@@ -38,35 +39,48 @@ public function addHandler(PatchOperationHandler $handler)
|
38 | 39 | }
|
39 | 40 |
|
40 | 41 | /**
|
| 42 | + * @param $subject |
| 43 | + * |
41 | 44 | * @return Sequence
|
| 45 | + * |
| 46 | + * @throws Exception\MissingOperationNameRequest |
| 47 | + * @throws Exception\MissingOperationRequest |
42 | 48 | */
|
43 |
| - public function getMatchedOperations() |
| 49 | + public function getMatchedOperations($subject) |
44 | 50 | {
|
45 | 51 | $handlers = $this->handlers;
|
46 | 52 | return $this->operations
|
47 | 53 | ->all()
|
48 | 54 | ->foldLeft(
|
49 | 55 | new Sequence(),
|
50 |
| - function (Sequence $matchedOperations, array $operationData) use ($handlers) { |
| 56 | + function (Sequence $matchedOperations, array $operationData) use ($handlers, $subject) { |
| 57 | + /** @var Option $handler */ |
51 | 58 | $handler = $handlers->find(function (PatchOperationHandler $handler) use ($operationData) {
|
52 | 59 | return $operationData[Operations::OP_KEY_NAME] === $handler->getName();
|
53 | 60 | });
|
54 | 61 | if ($handler->isDefined()) {
|
55 |
| - $matchedOperations->add(MatchedPatchOperation::create($operationData, $handler->get())); |
| 62 | + /** @var PatchOperationHandler $patchOperationHandler */ |
| 63 | + $patchOperationHandler = $handler->get(); |
| 64 | + if ($patchOperationHandler->canHandle($subject)) { |
| 65 | + $matchedOperations->add(MatchedPatchOperation::create($operationData, $handler->get())); |
| 66 | + } |
56 | 67 | }
|
57 | 68 | return $matchedOperations;
|
58 | 69 | }
|
59 | 70 | );
|
60 | 71 | }
|
61 | 72 |
|
62 | 73 | /**
|
| 74 | + * @param $subject |
| 75 | + * |
63 | 76 | * @return Sequence
|
| 77 | + * |
64 | 78 | * @throws Exception\MissingOperationNameRequest
|
65 | 79 | * @throws Exception\MissingOperationRequest
|
66 | 80 | */
|
67 |
| - public function getUnmatchedOperations() |
| 81 | + public function getUnmatchedOperations($subject) |
68 | 82 | {
|
69 |
| - $matchedOperations = $this->getMatchedOperations(); |
| 83 | + $matchedOperations = $this->getMatchedOperations($subject); |
70 | 84 | return $this->operations
|
71 | 85 | ->all()
|
72 | 86 | ->filter(function (array $operationData) use ($matchedOperations) {
|
|
0 commit comments