| Conditions | 9 |
| Paths | 9 |
| Total Lines | 89 |
| Code Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 46 | protected function performOperation(NodeValueInterface $element) |
||
| 47 | { |
||
| 48 | $operation = $this |
||
| 49 | ->queryProcessor |
||
| 50 | ->select($this->queryFactory->createQuery('/op'), $element) |
||
| 51 | ->decode(); |
||
| 52 | if (!is_string($operation)) { |
||
| 53 | throw new RuntimeException("Invalid patch operation"); |
||
| 54 | } |
||
| 55 | $pathQuery = $this->getOperationPath($element); |
||
| 56 | switch ($operation) { |
||
| 57 | case 'add': |
||
| 58 | $result = $this |
||
| 59 | ->queryProcessor |
||
| 60 | ->add( |
||
| 61 | $pathQuery, |
||
| 62 | $this->outputData, |
||
| 63 | $this->getOperationValue($element) |
||
| 64 | ); |
||
| 65 | $this->outputData = $this->getResultValue($result); |
||
| 66 | break; |
||
| 67 | |||
| 68 | case 'remove': |
||
| 69 | $result = $this |
||
| 70 | ->queryProcessor |
||
| 71 | ->delete($pathQuery, $this->outputData); |
||
| 72 | $this->outputData = $this->getResultValue($result); |
||
| 73 | break; |
||
| 74 | |||
| 75 | case 'replace': |
||
| 76 | $result = $this |
||
| 77 | ->queryProcessor |
||
| 78 | ->replace( |
||
| 79 | $pathQuery, |
||
| 80 | $this->outputData, |
||
| 81 | $this->getOperationValue($element) |
||
| 82 | ); |
||
| 83 | $this->outputData = $this->getResultValue($result); |
||
| 84 | break; |
||
| 85 | |||
| 86 | case 'test': |
||
| 87 | $result = $this |
||
| 88 | ->queryProcessor |
||
| 89 | ->select($pathQuery, $this->outputData); |
||
| 90 | if (!$result->exists()) { |
||
| 91 | throw new RuntimeException("Test operation failed"); |
||
| 92 | } |
||
| 93 | break; |
||
| 94 | |||
| 95 | case 'copy': |
||
| 96 | $fromResult = $this |
||
| 97 | ->queryProcessor |
||
| 98 | ->select( |
||
| 99 | $this->getOperationFrom($element), |
||
| 100 | $this->outputData |
||
| 101 | ); |
||
| 102 | $result = $this |
||
| 103 | ->queryProcessor |
||
| 104 | ->add( |
||
| 105 | $pathQuery, |
||
| 106 | $this->outputData, |
||
| 107 | $this->getResultValue($fromResult) |
||
| 108 | ); |
||
| 109 | $this->outputData = $this->getResultValue($result); |
||
| 110 | break; |
||
| 111 | |||
| 112 | case 'move': |
||
| 113 | $fromPathQuery = $this->getOperationFrom($element); |
||
| 114 | $fromResult = $this |
||
| 115 | ->queryProcessor |
||
| 116 | ->select($fromPathQuery, $this->outputData); |
||
| 117 | $removeResult = $this |
||
| 118 | ->queryProcessor |
||
| 119 | ->delete($fromPathQuery, $this->outputData); |
||
| 120 | $result = $this |
||
| 121 | ->queryProcessor |
||
| 122 | ->add( |
||
| 123 | $pathQuery, |
||
| 124 | $this->getResultValue($removeResult), |
||
| 125 | $this->getResultValue($fromResult) |
||
| 126 | ); |
||
| 127 | $this->outputData = $this->getResultValue($result); |
||
| 128 | break; |
||
| 129 | |||
| 130 | default: |
||
| 131 | throw new RuntimeException("Unknown operation '{$operation}'"); |
||
| 132 | } |
||
| 133 | |||
| 134 | return $this; |
||
| 135 | } |
||
| 192 |