| Conditions | 10 |
| Paths | 72 |
| Total Lines | 63 |
| 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 |
||
| 144 | public function addonToJson(Addon $package) |
||
| 145 | { |
||
| 146 | $tz = new DateTimeZone('UTC'); |
||
| 147 | |||
| 148 | $data = $package->toMap(); |
||
| 149 | unset($data['LastEdited']); |
||
| 150 | unset($data['Created']); |
||
| 151 | unset($data['ClassName']); |
||
| 152 | unset($data['RecordClassName']); |
||
| 153 | |||
| 154 | foreach (['Released', 'LastUpdated', 'LastBuilt'] as $field) { |
||
| 155 | if ($package->$field) { |
||
| 156 | $datetime = is_numeric($package->$field) ? "@" . $package->$field : $package->$field; |
||
| 157 | $data[$field] = new Datetime($datetime, $tz); |
||
| 158 | } |
||
| 159 | } |
||
| 160 | |||
| 161 | if ($package->RatingDetails) { |
||
| 162 | $data['RatingDetails'] = []; |
||
| 163 | foreach (json_decode($package->RatingDetails, true) as $k => $v) { |
||
| 164 | $data['RatingDetails'][] = [ |
||
| 165 | 'Name' => $k, |
||
| 166 | 'Value' => $v, |
||
| 167 | ]; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | $data['Versions'] = []; |
||
| 172 | foreach ($package->Versions() as $version) { |
||
| 173 | $versionData = $version->toMap(); |
||
| 174 | unset($versionData['LastEdited']); |
||
| 175 | unset($versionData['Created']); |
||
| 176 | unset($versionData['ClassName']); |
||
| 177 | unset($versionData['RecordClassName']); |
||
| 178 | unset($versionData['AddonID']); |
||
| 179 | |||
| 180 | if ($version->Released) { |
||
| 181 | $versionData['Released'] = new Datetime($version->Released, $tz); |
||
| 182 | } |
||
| 183 | |||
| 184 | foreach ($version->CompatibleVersions() as $compatible) { |
||
| 185 | $versionData['CompatibleVersions'][] = [ |
||
| 186 | "Version" => $compatible->Name, |
||
| 187 | "Major" => $compatible->Major, |
||
| 188 | "Minor" => $compatible->Minor, |
||
| 189 | ]; |
||
| 190 | } |
||
| 191 | |||
| 192 | foreach ($version->Authors() as $author) { |
||
| 193 | $authorData = $author->toMap(); |
||
| 194 | unset($authorData['ID']); |
||
| 195 | unset($authorData['ClassName']); |
||
| 196 | unset($authorData['RecordClassName']); |
||
| 197 | unset($authorData['LastEdited']); |
||
| 198 | unset($authorData['Created']); |
||
| 199 | $versionData['Authors'][] = $authorData; |
||
| 200 | } |
||
| 201 | |||
| 202 | $data['Versions'][] = $versionData; |
||
| 203 | } |
||
| 204 | |||
| 205 | return $data; |
||
| 206 | } |
||
| 207 | } |
||
| 208 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.