| Conditions | 9 |
| Paths | 47 |
| Total Lines | 54 |
| Code Lines | 31 |
| 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 |
||
| 125 | public function startNewJobForMergeTask(string $workflowId, array $filePaths, bool $enableTestMode = false): Job |
||
| 126 | { |
||
| 127 | $restApi = $this->restApi; |
||
| 128 | |||
| 129 | $filesCount = count($filePaths); |
||
| 130 | |||
| 131 | if (0 === $filesCount) { |
||
| 132 | throw new InvalidArgumentException('No input files specified'); |
||
| 133 | } |
||
| 134 | |||
| 135 | $filePath = $filePaths[0]; |
||
| 136 | |||
| 137 | if (1 === $filesCount) { |
||
| 138 | return $this->startNewJobWithFilePath($workflowId, $filePath); |
||
| 139 | } |
||
| 140 | |||
| 141 | $fileName = basename($filePath); |
||
| 142 | |||
| 143 | $fileNameMap = array(); |
||
| 144 | $fileNameMap[$fileName] = true; |
||
| 145 | |||
| 146 | $jobId = $restApi->createNewJobWithFilePathAndName($workflowId, $filePath, $fileName, false, $enableTestMode); |
||
| 147 | |||
| 148 | try { |
||
| 149 | for ($i = 1; $i < $filesCount; ++$i) { |
||
| 150 | $filePath = $filePaths[$i]; |
||
| 151 | $fileName = basename($filePath); |
||
| 152 | |||
| 153 | $pathInfo = pathinfo($filePath); |
||
| 154 | $fName = (isset($pathInfo['filename']) ? $pathInfo['filename'] : ''); |
||
| 155 | $fExt = (isset($pathInfo['extension']) ? $pathInfo['extension'] : ''); |
||
| 156 | |||
| 157 | $fNameIndex = 0; |
||
| 158 | while (isset($fileNameMap[$fileName])) { |
||
| 159 | ++$fNameIndex; |
||
| 160 | $fileName = $fName . ' (' . $fNameIndex . ').' . $fExt; |
||
| 161 | } |
||
| 162 | |||
| 163 | $fileNameMap[$fileName] = true; |
||
| 164 | |||
| 165 | $restApi->uploadInputWithFilePathAndName($jobId, $filePath, $fileName); |
||
| 166 | } |
||
| 167 | |||
| 168 | $restApi->startJob($jobId); |
||
| 169 | } catch (Exception $e) { |
||
| 170 | try { |
||
| 171 | $restApi->deleteJob($jobId); |
||
| 172 | } catch (Exception $eInner) { |
||
|
|
|||
| 173 | } |
||
| 174 | |||
| 175 | throw $e; |
||
| 176 | } |
||
| 177 | |||
| 178 | return new Job($restApi, $jobId); |
||
| 179 | } |
||
| 181 |