Conditions | 1 |
Paths | 1 |
Total Lines | 93 |
Code Lines | 76 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
104 | public function testReportFromString(): void |
||
105 | { |
||
106 | $contents = file_get_contents( |
||
107 | __DIR__ . '/../Fixture/report_js.json' |
||
108 | ); |
||
109 | $report = Report::fromString($contents); |
||
110 | |||
111 | $tags = $report->getTags(); |
||
112 | $contexts = $report->getContexts(); |
||
113 | $extras = $report->getExtras(); |
||
114 | $reports = $report->getReports(); |
||
115 | $user = $report->getUser(); |
||
116 | $message = $report->getUserMessage(); |
||
117 | $toJson = $report->toJson(); |
||
118 | |||
119 | $this->assertEquals((object) [ |
||
120 | 'server_software' => 'NginX/1.17 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.1e DAV/2 PHP/5.4.17', |
||
121 | 'user_agent_string' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36', |
||
122 | 'locale' => 'en', |
||
123 | 'configuration_storage' => true, |
||
124 | 'php_version' => '5.2.2', |
||
125 | 'exception_type' => null, |
||
126 | ], $tags); |
||
127 | $this->assertEquals((object) [ |
||
128 | 'os' => (object) ['name' => 'Windows'], |
||
129 | 'browser' => (object) [ |
||
130 | 'name' => 'FIREFOX', |
||
131 | 'version' => '17.5', |
||
132 | ], |
||
133 | ], $contexts); |
||
134 | $this->assertEquals((object) [], $extras); |
||
135 | $this->assertEquals((object) ['message' => ''], $message); |
||
136 | $this->assertEquals((object) ['ip_address' => '0.0.0.0'], $user); |
||
137 | $this->assertFalse($report->isMultiReports()); |
||
138 | $this->assertTrue($report->hasUserFeedback()); |
||
139 | $this->assertSame('<script>test steps', $report->getUserFeedback()); |
||
140 | $this->assertEquals([ |
||
141 | [ |
||
142 | 'sentry.interfaces.Message' => $message, |
||
143 | 'release' => '4.5.4.1', |
||
144 | 'dist' => '4.5.4.1deb2ubuntu2', |
||
145 | 'platform' => 'javascript', |
||
146 | 'environment' => 'production', |
||
147 | 'timestamp' => $report->getTimestampUTC(), |
||
148 | 'tags' => $tags, |
||
149 | 'contexts' => $contexts, |
||
150 | 'extra' => $extras, |
||
151 | 'user' => $user, |
||
152 | 'exception' => [ |
||
153 | 'values' => [ |
||
154 | (object) [ |
||
155 | 'type' => 'ReferenceError', |
||
156 | 'value' => 'a is not defined', |
||
157 | 'stacktrace' => (object) [ |
||
158 | 'frames' => [ |
||
159 | [ |
||
160 | 'platform' => 'javascript', |
||
161 | 'function' => 'PMA_exception', |
||
162 | 'lineno' => 312, |
||
163 | 'colno' => 5, |
||
164 | 'abs_path' => '', |
||
165 | 'filename' => '', |
||
166 | ], |
||
167 | [ |
||
168 | 'platform' => 'javascript', |
||
169 | 'function' => 'new_func', |
||
170 | 'lineno' => 257, |
||
171 | 'colno' => 33, |
||
172 | 'abs_path' => '', |
||
173 | 'filename' => '', |
||
174 | ], |
||
175 | ], |
||
176 | ], |
||
177 | ], |
||
178 | ], |
||
179 | ], |
||
180 | 'message' => 'a is not defined', |
||
181 | 'culprit' => 'tbl_relation.php', |
||
182 | 'event_id' => $report->getEventId(), |
||
183 | ], |
||
184 | ], $reports); |
||
185 | $this->assertEquals([ |
||
186 | 'sentry.interfaces.Message' => $message, |
||
187 | 'release' => '4.5.4.1', |
||
188 | 'dist' => '4.5.4.1deb2ubuntu2', |
||
189 | 'platform' => 'javascript', |
||
190 | 'timestamp' => $report->getTimestampUTC(), |
||
191 | 'tags' => $tags, |
||
192 | 'contexts' => $contexts, |
||
193 | 'extra' => $extras, |
||
194 | 'user' => $user, |
||
195 | 'environment' => 'production', |
||
196 | ], $toJson); |
||
197 | } |
||
199 |