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