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 |
||
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 | $datetime = is_numeric($package->$field) ? "@" . $package->$field : $package->$field; |
||
117 | $data[$field] = new Datetime($datetime, $tz); |
||
118 | } |
||
119 | } |
||
120 | |||
121 | if ($package->RatingDetails) { |
||
122 | $data['RatingDetails'] = []; |
||
123 | foreach (json_decode($package->RatingDetails, true) as $k => $v) { |
||
124 | $data['RatingDetails'][] = [ |
||
125 | 'Name' => $k, |
||
126 | 'Value' => $v, |
||
127 | ]; |
||
128 | } |
||
129 | } |
||
130 | |||
131 | $data['Versions'] = []; |
||
132 | foreach ($package->Versions() as $version) { |
||
133 | $versionData = $version->toMap(); |
||
134 | unset($versionData['LastEdited']); |
||
135 | unset($versionData['Created']); |
||
136 | unset($versionData['ClassName']); |
||
137 | unset($versionData['RecordClassName']); |
||
138 | unset($versionData['AddonID']); |
||
139 | |||
140 | if ($version->Released) { |
||
141 | $versionData['Released'] = new Datetime($version->Released, $tz); |
||
142 | } |
||
143 | |||
144 | foreach ($version->CompatibleVersions() as $compatible) { |
||
145 | $versionData['CompatibleVersions'][] = [ |
||
146 | "Version" => $compatible->Name, |
||
147 | "Major" => $compatible->Major, |
||
148 | "Minor" => $compatible->Minor, |
||
149 | ]; |
||
150 | } |
||
151 | |||
152 | foreach ($version->Authors() as $author) { |
||
153 | $authorData = $author->toMap(); |
||
154 | unset($authorData['ID']); |
||
155 | unset($authorData['ClassName']); |
||
156 | unset($authorData['RecordClassName']); |
||
157 | unset($authorData['LastEdited']); |
||
158 | unset($authorData['Created']); |
||
159 | $versionData['Authors'][] = $authorData; |
||
160 | } |
||
161 | |||
162 | $data['Versions'][] = $versionData; |
||
163 | } |
||
164 | |||
165 | return $data; |
||
166 | } |
||
167 | } |
||
168 |
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.