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