| Conditions | 18 |
| Paths | 254 |
| Total Lines | 59 |
| Code Lines | 36 |
| 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 |
||
| 82 | protected function fetch($ETag, $content) { |
||
| 83 | /** @var mixed[] $response */ |
||
| 84 | $response = parent::fetch($ETag, $content); |
||
| 85 | |||
| 86 | $allowPreReleases = $this->getChannel() === 'beta' || $this->getChannel() === 'daily'; |
||
| 87 | $allowNightly = $this->getChannel() === 'daily'; |
||
| 88 | |||
| 89 | foreach($response['data'] as $dataKey => $app) { |
||
| 90 | $releases = []; |
||
| 91 | |||
| 92 | // Filter all compatible releases |
||
| 93 | foreach($app['releases'] as $release) { |
||
| 94 | // Exclude all nightly and pre-releases if required |
||
| 95 | if (($allowNightly || $release['isNightly'] === false) |
||
| 96 | && ($allowPreReleases || strpos($release['version'], '-') === false)) { |
||
| 97 | // Exclude all versions not compatible with the current version |
||
| 98 | try { |
||
| 99 | $versionParser = new VersionParser(); |
||
| 100 | $version = $versionParser->getVersion($release['rawPlatformVersionSpec']); |
||
| 101 | $ncVersion = $this->getVersion(); |
||
| 102 | $min = $version->getMinimumVersion(); |
||
| 103 | $max = $version->getMaximumVersion(); |
||
| 104 | $minFulfilled = $this->compareVersion->isCompatible($ncVersion, $min, '>='); |
||
| 105 | $maxFulfilled = $max !== '' && |
||
| 106 | $this->compareVersion->isCompatible($ncVersion, $max, '<='); |
||
| 107 | if ($minFulfilled && ($this->ignoreMaxVersion || $maxFulfilled)) { |
||
| 108 | $releases[] = $release; |
||
| 109 | } |
||
| 110 | } catch (\InvalidArgumentException $e) { |
||
| 111 | $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::WARN]); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | if (empty($releases)) { |
||
| 117 | // Remove apps that don't have a matching release |
||
| 118 | continue; |
||
| 119 | } |
||
| 120 | |||
| 121 | // Get the highest version |
||
| 122 | $versions = []; |
||
| 123 | foreach($releases as $release) { |
||
| 124 | $versions[] = $release['version']; |
||
| 125 | } |
||
| 126 | usort($versions, 'version_compare'); |
||
| 127 | $versions = array_reverse($versions); |
||
| 128 | if(isset($versions[0])) { |
||
| 129 | $highestVersion = $versions[0]; |
||
| 130 | foreach ($releases as $release) { |
||
| 131 | if ((string)$release['version'] === (string)$highestVersion) { |
||
| 132 | $response['data'][$dataKey]['releases'] = [$release]; |
||
| 133 | break; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | $response['data'] = array_values($response['data']); |
||
| 140 | return $response; |
||
| 141 | } |
||
| 159 |