| Conditions | 13 |
| Paths | 25 |
| Total Lines | 68 |
| Code Lines | 39 |
| 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 |
||
| 33 | public function downloadByMessageIDs( |
||
| 34 | array|string $messageIDs, |
||
| 35 | string $groupName = '', |
||
| 36 | ?int $releaseId = null |
||
| 37 | ): array { |
||
| 38 | $result = [ |
||
| 39 | 'success' => false, |
||
| 40 | 'data' => null, |
||
| 41 | 'groupUnavailable' => false, |
||
| 42 | 'error' => null, |
||
| 43 | ]; |
||
| 44 | |||
| 45 | if (empty($messageIDs)) { |
||
| 46 | $result['error'] = 'No message IDs provided'; |
||
| 47 | return $result; |
||
| 48 | } |
||
| 49 | |||
| 50 | // Ensure array format |
||
| 51 | if (is_string($messageIDs)) { |
||
| 52 | $messageIDs = [$messageIDs]; |
||
| 53 | } |
||
| 54 | |||
| 55 | if ($this->config->debugMode) { |
||
| 56 | Log::debug('Attempting NNTP fetch', [ |
||
| 57 | 'release_id' => $releaseId, |
||
| 58 | 'message_ids' => $messageIDs, |
||
| 59 | 'group' => $groupName, |
||
| 60 | ]); |
||
| 61 | } |
||
| 62 | |||
| 63 | $binary = $this->nntp->getMessagesByMessageID($messageIDs, $this->config->alternateNNTP); |
||
| 64 | |||
| 65 | // Handle non-string or empty response as failure |
||
| 66 | if (! is_string($binary) || $binary === '') { |
||
| 67 | $errorMessage = null; |
||
| 68 | |||
| 69 | if (is_object($binary) && method_exists($binary, 'getMessage')) { |
||
| 70 | $errorMessage = $binary->getMessage(); |
||
| 71 | |||
| 72 | // Check for group unavailability |
||
| 73 | if (stripos($errorMessage, 'No such news group') !== false |
||
| 74 | || stripos($errorMessage, 'Group not found') !== false |
||
| 75 | ) { |
||
| 76 | $result['groupUnavailable'] = true; |
||
| 77 | $result['error'] = 'Group unavailable: '.$errorMessage; |
||
| 78 | return $result; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | if ($this->config->debugMode) { |
||
| 83 | Log::debug('NNTP fetch failed', [ |
||
| 84 | 'release_id' => $releaseId, |
||
| 85 | 'message_ids' => $messageIDs, |
||
| 86 | 'group' => $groupName, |
||
| 87 | 'error_object' => is_object($binary) ? get_class($binary) : null, |
||
| 88 | 'error_message' => $errorMessage, |
||
| 89 | 'raw_type' => gettype($binary), |
||
| 90 | 'length' => is_string($binary) ? strlen($binary) : 0, |
||
| 91 | ]); |
||
| 92 | } |
||
| 93 | |||
| 94 | $result['error'] = $errorMessage ?? 'Download failed'; |
||
| 95 | return $result; |
||
| 96 | } |
||
| 97 | |||
| 98 | $result['success'] = true; |
||
| 99 | $result['data'] = $binary; |
||
| 100 | return $result; |
||
| 101 | } |
||
| 204 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths