| Conditions | 15 |
| Paths | 404 |
| Total Lines | 93 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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 |
||
| 124 | private function processOperations($patchers, array $operations, array $args = array(), array $failures = array()) |
||
| 125 | { |
||
| 126 | list($operationName, $operationCode) = array_fill(0, 4, 'UNKNOWN'); |
||
| 127 | |||
| 128 | $variableFormats = array( |
||
| 129 | '{{%s}}' => array('escapeshellarg'), |
||
| 130 | '[[%s]]' => array() |
||
| 131 | ); |
||
| 132 | |||
| 133 | foreach ($patchers as $type => $patcher) { |
||
| 134 | $result = true; |
||
| 135 | |||
| 136 | if (!$patcher) { |
||
| 137 | continue; |
||
| 138 | } |
||
| 139 | |||
| 140 | $operationResults[$type] = array_fill_keys(array_keys($operations), ''); |
||
| 141 | |||
| 142 | foreach ($operations as $operationCode => $operationName) { |
||
| 143 | if (!isset($patcher[$operationCode])) { |
||
| 144 | continue; |
||
| 145 | } |
||
| 146 | |||
| 147 | $args = array_replace($args, $operationResults[$type]); |
||
| 148 | |||
| 149 | $applierOperations = is_array($patcher[$operationCode]) |
||
| 150 | ? $patcher[$operationCode] |
||
| 151 | : array($patcher[$operationCode]); |
||
| 152 | |||
| 153 | foreach ($applierOperations as $operation) { |
||
| 154 | $passOnFailure = strpos($operation, '!') === 0; |
||
| 155 | $operation = ltrim($operation, '!'); |
||
| 156 | |||
| 157 | $command = $this->templateUtils->compose($operation, $args, $variableFormats); |
||
| 158 | |||
| 159 | $cwd = $this->extractStringValue($args, PluginConfig::PATCHER_ARG_CWD); |
||
| 160 | |||
| 161 | $resultKey = $cwd . ' | ' . $command; |
||
| 162 | |||
| 163 | if ($passOnFailure) { |
||
| 164 | $this->logger->writeVerbose( |
||
| 165 | \Vaimo\ComposerPatches\Logger::TYPE_NONE, |
||
| 166 | '<comment>***</comment> ' |
||
| 167 | . 'The expected result to execution is a failure' |
||
| 168 | . '<comment>***</comment>' |
||
| 169 | ); |
||
| 170 | } |
||
| 171 | |||
| 172 | if (!isset($this->resultCache[$resultKey])) { |
||
| 173 | $this->resultCache[$resultKey] = $this->shell->execute($command, $cwd); |
||
| 174 | } |
||
| 175 | |||
| 176 | list($result, $output) = $this->resultCache[$resultKey]; |
||
| 177 | |||
| 178 | if ($result) { |
||
| 179 | $result = $this->scanOutputForFailures( |
||
| 180 | $output, |
||
| 181 | $this->extractArrayValue($failures, $operationCode) |
||
| 182 | ); |
||
| 183 | } |
||
| 184 | |||
| 185 | if ($passOnFailure) { |
||
| 186 | $result = !$result; |
||
| 187 | } |
||
| 188 | |||
| 189 | if (!$result) { |
||
| 190 | continue; |
||
| 191 | } |
||
| 192 | |||
| 193 | $operationResults[$type][$operationCode] = $output; |
||
| 194 | |||
| 195 | break; |
||
| 196 | } |
||
| 197 | |||
| 198 | if (!$result) { |
||
| 199 | break; |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | if ($result) { |
||
| 204 | return $type; |
||
| 205 | } |
||
| 206 | |||
| 207 | $messageArgs = array( |
||
| 208 | is_string($operationName) ? $operationName : $operationCode, |
||
| 209 | $type, |
||
| 210 | $this->extractStringValue($args, PluginConfig::PATCHER_ARG_LEVEL) |
||
| 211 | ); |
||
| 212 | |||
| 213 | $this->logger->writeVerbose('warning', '%s (type=%s) failed with p=%s', $messageArgs); |
||
| 214 | } |
||
| 215 | |||
| 216 | return ''; |
||
| 217 | } |
||
| 256 |