Conditions | 1 |
Paths | 1 |
Total Lines | 89 |
Code Lines | 72 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
25 | public function testReportFromString(): void |
||
26 | { |
||
27 | $contents = file_get_contents( |
||
28 | __DIR__ . '/../Fixture/report_js.json' |
||
29 | ); |
||
30 | $report = Report::fromString($contents); |
||
31 | |||
32 | $tags = $report->getTags(); |
||
33 | $contexts = $report->getContexts(); |
||
34 | $extras = $report->getExtras(); |
||
35 | $reports = $report->getReports(); |
||
36 | $user = $report->getUser(); |
||
37 | $message = $report->getUserMessage(); |
||
38 | $toJson = $report->toJson(); |
||
39 | |||
40 | $this->assertEquals((object) [ |
||
41 | 'server_software' => 'NginX/1.17 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.1e DAV/2 PHP/5.4.17', |
||
42 | 'user_agent_string' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36', |
||
43 | 'locale' => 'en', |
||
44 | 'configuration_storage' => true, |
||
45 | 'php_version' => '5.2.2', |
||
46 | 'exception_type' => null, |
||
47 | ], $tags); |
||
48 | $this->assertEquals((object) [ |
||
49 | 'os' => (object) ['name' => 'Windows'], |
||
50 | 'browser' => (object) [ |
||
51 | 'name' => 'FIREFOX', |
||
52 | 'version' => '17.5', |
||
53 | ], |
||
54 | ], $contexts); |
||
55 | $this->assertEquals((object) [], $extras); |
||
56 | $this->assertEquals((object) ['message' => ''], $message); |
||
57 | $this->assertEquals((object) ['ip_address' => '0.0.0.0'], $user); |
||
58 | $this->assertFalse($report->isMultiReports()); |
||
59 | $this->assertTrue($report->hasUserFeedback()); |
||
60 | $this->assertSame('<script>test steps', $report->getUserFeedback()); |
||
61 | $this->assertEquals([ |
||
62 | [ |
||
63 | 'sentry.interfaces.Message' => $message, |
||
64 | 'release' => '4.5.4.1deb2ubuntu2', |
||
65 | 'platform' => 'javascript', |
||
66 | 'timestamp' => $report->getTimestampUTC(), |
||
67 | 'tags' => $tags, |
||
68 | 'contexts' => $contexts, |
||
69 | 'extra' => $extras, |
||
70 | 'user' => $user, |
||
71 | 'exception' => [ |
||
72 | 'values' => [ |
||
73 | (object) [ |
||
74 | 'type' => 'ReferenceError', |
||
75 | 'value' => 'a is not defined', |
||
76 | 'stacktrace' => (object) [ |
||
77 | 'frames' => [ |
||
78 | [ |
||
79 | 'platform' => 'javascript', |
||
80 | 'function' => 'PMA_exception', |
||
81 | 'lineno' => 312, |
||
82 | 'colno' => 5, |
||
83 | 'abs_path' => '', |
||
84 | 'filename' => '', |
||
85 | ], |
||
86 | [ |
||
87 | 'platform' => 'javascript', |
||
88 | 'function' => 'new_func', |
||
89 | 'lineno' => 257, |
||
90 | 'colno' => 33, |
||
91 | 'abs_path' => '', |
||
92 | 'filename' => '', |
||
93 | ], |
||
94 | ], |
||
95 | ], |
||
96 | ], |
||
97 | ], |
||
98 | ], |
||
99 | 'message' => 'a is not defined', |
||
100 | 'culprit' => 'tbl_relation.php', |
||
101 | 'event_id' => $report->getEventId(), |
||
102 | ], |
||
103 | ], $reports); |
||
104 | $this->assertEquals([ |
||
105 | 'sentry.interfaces.Message' => $message, |
||
106 | 'release' => '4.5.4.1deb2ubuntu2', |
||
107 | 'platform' => 'javascript', |
||
108 | 'timestamp' => $report->getTimestampUTC(), |
||
109 | 'tags' => $tags, |
||
110 | 'contexts' => $contexts, |
||
111 | 'extra' => $extras, |
||
112 | 'user' => $user, |
||
113 | ], $toJson); |
||
114 | } |
||
116 |