| Conditions | 6 |
| Paths | 10 |
| Total Lines | 65 |
| Code Lines | 46 |
| 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 |
||
| 86 | public function process(array $patches, array $packagesByName) |
||
| 87 | { |
||
| 88 | $ownerName = $this->ownerPackage->getName(); |
||
| 89 | $relativePath = PathUtils::composePath($ownerName, 'downloads'); |
||
| 90 | $absolutePath = PathUtils::composePath($this->vendorDir, $relativePath); |
||
| 91 | $errors = array(); |
||
| 92 | $compExecutor = $this->compExecutor; |
||
| 93 | $errorHandler = $this->errorHandler; |
||
| 94 | |||
| 95 | foreach ($patches as &$packagePatches) { |
||
| 96 | foreach ($packagePatches as &$patchData) { |
||
| 97 | if (!$patchData[PatchDefinition::URL]) { |
||
| 98 | continue; |
||
| 99 | } |
||
| 100 | |||
| 101 | $source = $patchData[PatchDefinition::URL]; |
||
| 102 | $checksum = $patchData[PatchDefinition::CHECKSUM]; |
||
| 103 | $hashComponents = array($source, $checksum); |
||
| 104 | $sourceHash = md5(implode('|', $hashComponents)); |
||
| 105 | $package = $this->createPackage($source, $sourceHash, $relativePath, $checksum); |
||
| 106 | $destDir = PathUtils::composePath($absolutePath, $sourceHash); |
||
| 107 | $destinationFile = PathUtils::composePath($destDir, basename($source)); |
||
| 108 | |||
| 109 | try { |
||
| 110 | $downloader = $this->fileDownloader; |
||
| 111 | |||
| 112 | $this->consoleSilencer->applyToCallback( |
||
| 113 | function () use ( |
||
| 114 | $errorHandler, |
||
| 115 | $downloader, |
||
| 116 | $compExecutor, |
||
| 117 | $package, |
||
| 118 | $destDir, |
||
| 119 | $source, |
||
| 120 | &$patchData, |
||
| 121 | &$errors |
||
| 122 | ) { |
||
| 123 | $compExecutor->downloadPackage( |
||
| 124 | $downloader, |
||
| 125 | $package, |
||
| 126 | $source, |
||
| 127 | $destDir, |
||
| 128 | $errorHandler, |
||
| 129 | $patchData, |
||
| 130 | $errors |
||
| 131 | ); |
||
| 132 | } |
||
| 133 | ); |
||
| 134 | } catch (\Composer\Downloader\TransportException $exception) { |
||
| 135 | $patchData[PatchDefinition::STATUS_LABEL] = $errorHandler->handleError($source, $exception); |
||
| 136 | $patchData[PatchDefinition::STATUS] = PatchDefinition::STATUS_ERRORS; |
||
| 137 | } |
||
| 138 | |||
| 139 | $compExecutor->assignTmpPathForPatchData($patchData, $destinationFile); |
||
| 140 | $patchData[PatchDefinition::TMP] = true; |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | $compExecutor->waitDownloadCompletion($this->composer); |
||
| 145 | |||
| 146 | if (count($errors) > 0) { |
||
| 147 | throw array_shift($errors); |
||
| 148 | } |
||
| 149 | |||
| 150 | return $patches; |
||
| 151 | } |
||
| 169 |