Conditions | 1 |
Paths | 1 |
Total Lines | 99 |
Code Lines | 80 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
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 |
||
175 | public function testReportFromString(): void |
||
176 | { |
||
177 | $contents = file_get_contents( |
||
178 | __DIR__ . '/../Fixture/report_js.json' |
||
179 | ); |
||
180 | $report = Report::fromString($contents); |
||
181 | |||
182 | $tags = $report->getTags(); |
||
183 | $contexts = $report->getContexts(); |
||
184 | $extras = $report->getExtras(); |
||
185 | $reports = $report->getReports(); |
||
186 | $user = $report->getUser(); |
||
187 | $message = $report->getUserMessage(); |
||
188 | $toJson = $report->toJson(); |
||
189 | |||
190 | $this->assertEquals((object) [ |
||
191 | 'server_software' => 'NginX/1.17 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.1e DAV/2 PHP/5.4.17', |
||
192 | 'user_agent_string' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36', |
||
193 | 'locale' => 'en', |
||
194 | 'configuration_storage' => true, |
||
195 | 'php_version' => '5.2.2', |
||
196 | 'exception_type' => null, |
||
197 | ], $tags); |
||
198 | $this->assertEquals((object) [ |
||
199 | 'os' => (object) ['name' => 'Windows'], |
||
200 | 'browser' => (object) [ |
||
201 | 'name' => 'FIREFOX', |
||
202 | 'version' => '17.5', |
||
203 | ], |
||
204 | ], $contexts); |
||
205 | $this->assertEquals((object) [], $extras); |
||
206 | $this->assertEquals((object) ['message' => ''], $message); |
||
207 | $this->assertEquals( |
||
208 | (object) [ |
||
209 | 'ip_address' => '0.0.0.0', |
||
210 | 'id' => '90244836bc888d4b4bb8449010dba862ebc5a8905a79da8269b4e76d08831226', |
||
211 | ], |
||
212 | $user |
||
213 | ); |
||
214 | $this->assertFalse($report->isMultiReports()); |
||
215 | $this->assertTrue($report->hasUserFeedback()); |
||
216 | $this->assertSame('<script>test steps', $report->getUserFeedback()); |
||
217 | $this->assertEquals([ |
||
218 | [ |
||
219 | 'sentry.interfaces.Message' => $message, |
||
220 | 'release' => '4.5.4.1', |
||
221 | 'dist' => '4.5.4.1deb2ubuntu2', |
||
222 | 'platform' => 'javascript', |
||
223 | 'environment' => 'production', |
||
224 | 'timestamp' => $report->getTimestampUTC(), |
||
225 | 'tags' => $tags, |
||
226 | 'contexts' => $contexts, |
||
227 | 'extra' => $extras, |
||
228 | 'user' => $user, |
||
229 | 'exception' => [ |
||
230 | 'values' => [ |
||
231 | (object) [ |
||
232 | 'type' => 'ReferenceError', |
||
233 | 'value' => 'a is not defined', |
||
234 | 'stacktrace' => (object) [ |
||
235 | 'frames' => [ |
||
236 | [ |
||
237 | 'platform' => 'javascript', |
||
238 | 'function' => 'PMA_exception', |
||
239 | 'lineno' => 312, |
||
240 | 'colno' => 5, |
||
241 | 'abs_path' => '', |
||
242 | 'filename' => '', |
||
243 | ], |
||
244 | [ |
||
245 | 'platform' => 'javascript', |
||
246 | 'function' => 'new_func', |
||
247 | 'lineno' => 257, |
||
248 | 'colno' => 33, |
||
249 | 'abs_path' => '', |
||
250 | 'filename' => '', |
||
251 | ], |
||
252 | ], |
||
253 | ], |
||
254 | ], |
||
255 | ], |
||
256 | ], |
||
257 | 'message' => 'a is not defined', |
||
258 | 'culprit' => 'tbl_relation.php', |
||
259 | 'event_id' => $report->getEventId(), |
||
260 | ], |
||
261 | ], $reports); |
||
262 | $this->assertEquals([ |
||
263 | 'sentry.interfaces.Message' => $message, |
||
264 | 'release' => '4.5.4.1', |
||
265 | 'dist' => '4.5.4.1deb2ubuntu2', |
||
266 | 'platform' => 'javascript', |
||
267 | 'timestamp' => $report->getTimestampUTC(), |
||
268 | 'tags' => $tags, |
||
269 | 'contexts' => $contexts, |
||
270 | 'extra' => $extras, |
||
271 | 'user' => $user, |
||
272 | 'environment' => 'production', |
||
273 | ], $toJson); |
||
274 | } |
||
276 |