| Conditions | 17 |
| Paths | 10 |
| Total Lines | 159 |
| 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 |
||
| 81 | private function generatePackageList() |
||
| 82 | { |
||
| 83 | // Get packages |
||
| 84 | $packagesData = $this->getPackagesJsonData; |
||
| 85 | |||
| 86 | // Discard those not on this branch |
||
| 87 | $relevantPackages = $packagesData[$this->branch]; |
||
| 88 | |||
| 89 | // Latest release in this branch is... |
||
| 90 | $release = $relevantPackages['release']; |
||
| 91 | |||
| 92 | // Generate from versions |
||
| 93 | $this->fromVersions = explode(',', $relevantPackages['updates']['from']); |
||
| 94 | |||
| 95 | // Check selected version is a valid version |
||
| 96 | if (!in_array($this->selectedVersion, $this->fromVersions)) |
||
| 97 | { |
||
| 98 | $update = false; |
||
| 99 | } |
||
| 100 | |||
| 101 | // Link to the packages for this release. Add filenames on here for download urls. |
||
| 102 | $download_base_link = 'https://download.phpbb.com/pub/release/' . $this->branch . '/' . $release . '/'; |
||
| 103 | |||
| 104 | $hashCaches = 0; |
||
| 105 | $packagesTotal = 0; |
||
| 106 | |||
| 107 | // If we haven't established it's an update (and have an update from version) |
||
| 108 | if (!$this->update) |
||
| 109 | { |
||
| 110 | // Discard irrlevant data |
||
| 111 | $packages = array( |
||
| 112 | 'package' => $relevantPackages['package']['release'], |
||
| 113 | 'patch' => $relevantPackages['updates']['patch'], |
||
| 114 | 'changed-files' => $relevantPackages['updates']['changed-files'], |
||
| 115 | ); |
||
| 116 | |||
| 117 | foreach ($packages as $package) |
||
| 118 | { |
||
| 119 | // URL to this specific package |
||
| 120 | $url = $download_base_link . $package['filename']; |
||
| 121 | |||
| 122 | // Generate sha256/md5 hashes for packages |
||
| 123 | $hash = $this->gethash($packages[$package]['filename'], $url); |
||
| 124 | |||
| 125 | // Make use of the stuff we just generated by putting it back in ready for templates |
||
| 126 | $packages[$package]['url'] = $url; |
||
| 127 | $packages[$package]['hash'] = $hash['hash']; |
||
| 128 | $packages[$package]['hashType'] = $hash['hashType']; |
||
| 129 | |||
| 130 | // Counts |
||
| 131 | $packagesTotal++; |
||
| 132 | ($hash['hashCacheStatus'] == 'Hit') ? $hashCaches++ : null; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | else |
||
| 136 | { |
||
| 137 | // Discard irrlevant data |
||
| 138 | $packages = array( |
||
| 139 | 'package' => $relevantPackages['package']['release'], |
||
| 140 | ); |
||
| 141 | |||
| 142 | foreach ($relevantPackages['updates']['changed-files'] as $changedFilesPackage) |
||
| 143 | { |
||
| 144 | if ($changedFilesPackage['from'] == $this->selectedVersion) |
||
| 145 | { |
||
| 146 | // URL to this specific package |
||
| 147 | $url = $download_base_link . $changedFilesPackage['filename']; |
||
| 148 | |||
| 149 | // Generate sha256/md5 hashes for packages |
||
| 150 | $hash = $this->gethash($changedFilesPackage['filename'], $url); |
||
| 151 | |||
| 152 | // Make use of the stuff we just generated by putting it back in ready for templates |
||
| 153 | $changedFilesPackage['url'] = $url; |
||
| 154 | $changedFilesPackage['hash'] = $hash['hash']; |
||
| 155 | $changedFilesPackage['hashType'] = $hash['hashType']; |
||
| 156 | |||
| 157 | // Counts |
||
| 158 | $packagesTotal++; |
||
| 159 | ($hash['hashCacheStatus'] == 'Hit') ? $hashCaches++ : null; |
||
| 160 | |||
| 161 | $packages['changed_files'] = $changedFilesPackage; |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 165 | foreach ($relevantPackages['updates']['patch'] as $patchFilesPackage) |
||
| 166 | { |
||
| 167 | if ($patchFilesPackage['from'] == $this->selectedVersion) |
||
| 168 | { |
||
| 169 | // URL to this specific package |
||
| 170 | $url = $download_base_link . $patchFilesPackage['filename']; |
||
| 171 | |||
| 172 | // Generate sha256/md5 hashes for packages |
||
| 173 | $hash = $this->gethash($patchFilesPackage['filename'], $url); |
||
| 174 | |||
| 175 | // Make use of the stuff we just generated by putting it back in ready for templates |
||
| 176 | $patchFilesPackage['url'] = $url; |
||
| 177 | $patchFilesPackage['hash'] = $hash['hash']; |
||
| 178 | $patchFilesPackage['hashType'] = $hash['hashType']; |
||
| 179 | |||
| 180 | // Counts |
||
| 181 | $packagesTotal++; |
||
| 182 | ($hash['hashCacheStatus'] == 'Hit') ? $hashCaches++ : null; |
||
| 183 | |||
| 184 | $packages['patch'] = $patchFilesPackage; |
||
| 185 | } |
||
| 186 | } |
||
| 187 | |||
| 188 | foreach ($relevantPackages['updates']['code-changes'] as $ccFilesPackage) |
||
| 189 | { |
||
| 190 | if ($ccFilesPackage['from'] == $this->selectedVersion) |
||
| 191 | { |
||
| 192 | // URL to this specific package |
||
| 193 | $url = $download_base_link . $ccFilesPackage['filename']; |
||
| 194 | |||
| 195 | // Generate sha256/md5 hashes for packages |
||
| 196 | $hash = $this->gethash($ccFilesPackage['filename'], $url); |
||
| 197 | |||
| 198 | // Make use of the stuff we just generated by putting it back in ready for templates |
||
| 199 | $ccFilesPackage['url'] = $url; |
||
| 200 | $ccFilesPackage['hash'] = $hash['hash']; |
||
| 201 | $ccFilesPackage['hashType'] = $hash['hashType']; |
||
| 202 | |||
| 203 | // Counts |
||
| 204 | $packagesTotal++; |
||
| 205 | ($hash['hashCacheStatus'] == 'Hit') ? $hashCaches++ : null; |
||
| 206 | |||
| 207 | $packages['code-changes'] = $ccFilesPackage; |
||
| 208 | } |
||
| 209 | } |
||
| 210 | |||
| 211 | foreach ($relevantPackages['updates']['automatic-updaters'] as $automaticFilesPackage) |
||
| 212 | { |
||
| 213 | if ($automaticFilesPackage['from'] == $this->selectedVersion) |
||
| 214 | { |
||
| 215 | // URL to this specific package |
||
| 216 | $url = $download_base_link . $automaticFilesPackage['filename']; |
||
| 217 | |||
| 218 | // Generate sha256/md5 hashes for packages |
||
| 219 | $hash = $this->gethash($automaticFilesPackage['filename'], $url); |
||
| 220 | |||
| 221 | // Make use of the stuff we just generated by putting it back in ready for templates |
||
| 222 | $automaticFilesPackage['url'] = $url; |
||
| 223 | $automaticFilesPackage['hash'] = $hash['hash']; |
||
| 224 | $automaticFilesPackage['hashType'] = $hash['hashType']; |
||
| 225 | |||
| 226 | // Counts |
||
| 227 | $packagesTotal++; |
||
| 228 | ($hash['hashCacheStatus'] == 'Hit') ? $hashCaches++ : null; |
||
| 229 | |||
| 230 | $packages['automatic-updater'] = $automaticFilesPackage; |
||
| 231 | } |
||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | $this->packages = $packages; |
||
| 236 | $this->caching = array($cacheStatus, $hashCaches, $packagesTotal); |
||
| 237 | |||
| 238 | return; |
||
| 239 | } |
||
| 240 | |||
| 274 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.