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