| Conditions | 9 |
| Paths | 6 |
| Total Lines | 74 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 24 | public function normalize($target, $label, array $data, array $ownerConfig) |
||
| 25 | { |
||
| 26 | if (!isset($ownerConfig[PluginConfig::PATCHES_BASE])) { |
||
| 27 | return array(); |
||
| 28 | } |
||
| 29 | |||
| 30 | $source = $data[PatchDefinition::SOURCE]; |
||
| 31 | |||
| 32 | if (parse_url($source, PHP_URL_SCHEME)) { |
||
| 33 | return array(); |
||
| 34 | } |
||
| 35 | |||
| 36 | if (is_numeric($label) && isset($data[PatchDefinition::LABEL])) { |
||
| 37 | $label = $data[PatchDefinition::LABEL]; |
||
| 38 | } |
||
| 39 | |||
| 40 | if (strpos($data[PatchDefinition::PATH], DIRECTORY_SEPARATOR) === 0 |
||
| 41 | && file_exists($data[PatchDefinition::PATH]) |
||
| 42 | ) { |
||
| 43 | return array( |
||
| 44 | PatchDefinition::LABEL => $label, |
||
| 45 | PatchDefinition::SOURCE => $source |
||
| 46 | ); |
||
| 47 | } |
||
| 48 | |||
| 49 | $template = $this->resolveTemplate($ownerConfig, $target); |
||
| 50 | |||
| 51 | list ($sourcePath, $sourceTags) = $this->deconstructSource($source); |
||
| 52 | |||
| 53 | $nameParts = explode(ComposerConstants::PACKAGE_SEPARATOR, $target); |
||
| 54 | |||
| 55 | $pathVariables = array( |
||
| 56 | 'file' => $sourcePath, |
||
| 57 | 'vendor' => array_shift($nameParts), |
||
| 58 | 'package' => implode(ComposerConstants::PACKAGE_SEPARATOR, $nameParts), |
||
| 59 | 'label' => $label |
||
| 60 | ); |
||
| 61 | |||
| 62 | $mutationNamesMap = array( |
||
| 63 | 'file' => 'file name', |
||
| 64 | 'vendor' => 'vendor name', |
||
| 65 | 'package' => 'module name', |
||
| 66 | 'label' => 'label value' |
||
| 67 | ); |
||
| 68 | |||
| 69 | $extraVariables = array( |
||
| 70 | 'version' => preg_replace( |
||
| 71 | '/[^A-Za-z0-9.-]/', |
||
| 72 | '', |
||
| 73 | strtok(reset($data[PatchDefinition::DEPENDS]) ?: '0.0.0', ' ') |
||
| 74 | ), |
||
| 75 | 'file' => $sourcePath, |
||
| 76 | 'label' => $label |
||
| 77 | ); |
||
| 78 | |||
| 79 | $variablePattern = '{{%s}}'; |
||
| 80 | |||
| 81 | $pathVariables = $this->expandPathVariables($pathVariables, $mutationNamesMap); |
||
| 82 | |||
| 83 | $templateVariables = $this->prepareTemplateValues( |
||
| 84 | $template, |
||
| 85 | $variablePattern, |
||
| 86 | array_replace($pathVariables, $extraVariables) |
||
| 87 | ); |
||
| 88 | |||
| 89 | $sourcePath = $this->templateUtils->compose( |
||
| 90 | $template . ($sourceTags ? ('#' . $sourceTags) : ''), |
||
| 91 | $templateVariables, |
||
| 92 | array_fill_keys(array($variablePattern), array()) |
||
| 93 | ); |
||
| 94 | |||
| 95 | return array( |
||
| 96 | PatchDefinition::LABEL => $this->normalizeLabelForSourcePath($label, $sourcePath), |
||
| 97 | PatchDefinition::SOURCE => $sourcePath |
||
| 98 | ); |
||
| 219 |