| Conditions | 5 |
| Paths | 8 |
| Total Lines | 63 |
| Code Lines | 38 |
| 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 |
||
| 58 | public function applyFile($filename, $cwd, array $config = array()) |
||
| 59 | { |
||
| 60 | $applierConfig = $this->applierUtils->mergeApplierConfig($this->config, array_filter($config)); |
||
| 61 | |||
| 62 | $applierConfig = $this->applierUtils->sortApplierConfig($applierConfig); |
||
| 63 | |||
| 64 | $patchers = $this->extractArrayValue($applierConfig, PluginConfig::PATCHER_APPLIERS); |
||
| 65 | $operations = $this->extractArrayValue($applierConfig, PluginConfig::PATCHER_OPERATIONS); |
||
| 66 | $levels = $this->extractArrayValue($applierConfig, PluginConfig::PATCHER_LEVELS); |
||
| 67 | $failureMessages = $this->extractArrayValue($applierConfig, PluginConfig::PATCHER_FAILURES); |
||
| 68 | |||
| 69 | $sanityOperations = $this->extractArrayValue($applierConfig, PluginConfig::PATCHER_SANITY); |
||
| 70 | |||
| 71 | try { |
||
| 72 | $this->applierUtils->validateConfig($applierConfig); |
||
| 73 | } catch (\Vaimo\ComposerPatches\Exceptions\ConfigValidationException $exception) { |
||
| 74 | $this->logger->writeVerbose('error', $exception->getMessage()); |
||
| 75 | } |
||
| 76 | |||
| 77 | $arguments = array( |
||
| 78 | PluginConfig::PATCHER_ARG_FILE => $filename, |
||
| 79 | PluginConfig::PATCHER_ARG_CWD => $cwd |
||
| 80 | ); |
||
| 81 | |||
| 82 | $patcherName = $this->processOperations($patchers, $sanityOperations, $arguments); |
||
| 83 | |||
| 84 | if (!$patcherName) { |
||
| 85 | $message = sprintf( |
||
| 86 | 'None of the patch appliers seem to be available (tried: %s)', |
||
| 87 | implode(', ', array_keys($patchers)) |
||
| 88 | ); |
||
| 89 | |||
| 90 | throw new \Vaimo\ComposerPatches\Exceptions\RuntimeException($message); |
||
| 91 | } |
||
| 92 | |||
| 93 | foreach ($levels as $patchLevel) { |
||
| 94 | $arguments = array_replace( |
||
| 95 | $arguments, |
||
| 96 | array(PluginConfig::PATCHER_ARG_LEVEL => $patchLevel) |
||
| 97 | ); |
||
| 98 | |||
| 99 | $patcherName = $this->processOperations( |
||
| 100 | $patchers, |
||
| 101 | $operations, |
||
| 102 | $arguments, |
||
| 103 | $failureMessages |
||
| 104 | ); |
||
| 105 | |||
| 106 | if (!$patcherName) { |
||
| 107 | continue; |
||
| 108 | } |
||
| 109 | |||
| 110 | $this->logger->writeVerbose( |
||
| 111 | 'info', |
||
| 112 | 'SUCCESS with type=%s (p=%s)', |
||
| 113 | array($patcherName, $patchLevel) |
||
| 114 | ); |
||
| 115 | |||
| 116 | return; |
||
| 117 | } |
||
| 118 | |||
| 119 | throw new \Exception( |
||
| 120 | sprintf('Cannot apply patch %s', $filename) |
||
| 121 | ); |
||
| 256 |