| Conditions | 8 |
| Paths | 54 |
| Total Lines | 60 |
| 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 |
||
| 104 | public function addonToJson(Addon $package) |
||
| 105 | { |
||
| 106 | $tz = new DateTimeZone('UTC'); |
||
| 107 | |||
| 108 | $data = $package->toMap(); |
||
| 109 | unset($data['LastEdited']); |
||
| 110 | unset($data['Created']); |
||
| 111 | unset($data['ClassName']); |
||
| 112 | unset($data['RecordClassName']); |
||
| 113 | |||
| 114 | foreach (['Released', 'LastUpdated', 'LastBuilt'] as $field) { |
||
| 115 | if ($package->$field) { |
||
| 116 | $data[$field] = new Datetime($package->$field, $tz); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | $data['RatingDetails'] = []; |
||
| 121 | foreach (json_decode($package->RatingDetails, true) as $k => $v) { |
||
| 122 | $data['RatingDetails'][] = [ |
||
| 123 | 'Name' => $k, |
||
| 124 | 'Value' => $v, |
||
| 125 | ]; |
||
| 126 | } |
||
| 127 | |||
| 128 | $data['Versions'] = []; |
||
| 129 | foreach ($package->Versions() as $version) { |
||
| 130 | $versionData = $version->toMap(); |
||
| 131 | unset($versionData['LastEdited']); |
||
| 132 | unset($versionData['Created']); |
||
| 133 | unset($versionData['ClassName']); |
||
| 134 | unset($versionData['RecordClassName']); |
||
| 135 | unset($versionData['AddonID']); |
||
| 136 | |||
| 137 | if ($version->Released) { |
||
| 138 | $versionData['Released'] = new Datetime($version->Released, $tz); |
||
| 139 | } |
||
| 140 | |||
| 141 | foreach ($version->CompatibleVersions() as $compatible) { |
||
| 142 | $versionData['CompatibleVersions'][] = [ |
||
| 143 | "Version" => $compatible->Name, |
||
| 144 | "Major" => $compatible->Major, |
||
| 145 | "Minor" => $compatible->Minor, |
||
| 146 | ]; |
||
| 147 | } |
||
| 148 | |||
| 149 | foreach ($version->Authors() as $author) { |
||
| 150 | $authorData = $author->toMap(); |
||
| 151 | unset($authorData['ID']); |
||
| 152 | unset($authorData['ClassName']); |
||
| 153 | unset($authorData['RecordClassName']); |
||
| 154 | unset($authorData['LastEdited']); |
||
| 155 | unset($authorData['Created']); |
||
| 156 | $versionData['Authors'][] = $authorData; |
||
| 157 | } |
||
| 158 | |||
| 159 | $data['Versions'][] = $versionData; |
||
| 160 | } |
||
| 161 | |||
| 162 | return $data; |
||
| 163 | } |
||
| 164 | } |
||
| 165 |
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.