Conditions | 1 |
Paths | 1 |
Total Lines | 76 |
Code Lines | 35 |
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 |
||
179 | public function testGenerateNoGroupsAndGroups(): void |
||
180 | { |
||
181 | $user = 'jwage'; |
||
182 | $repository = 'changelog-generator'; |
||
183 | $milestone = '1.0'; |
||
184 | |||
185 | $outputStream = fopen('php://memory', 'rwb+'); |
||
186 | |||
187 | self::assertNotFalse($outputStream); |
||
188 | |||
189 | $output = new StreamOutput($outputStream); |
||
190 | |||
191 | $pullRequest1 = new Issue(3, 'Issue #3', 'Test Body', 'https://example.com/3', 'Ocramius', [], true); |
||
192 | $pullRequest2 = new Issue(4, 'Issue #4', 'Test Body', 'https://example.com/4', 'romanb', [], true); |
||
193 | |||
194 | $issue1 = new Issue(1, 'Issue #1', 'Test Body', 'https://example.com/1', 'jwage', [], false); |
||
195 | $issue1->setLinkedPullRequest($pullRequest1); |
||
196 | |||
197 | $issue2 = new Issue(2, 'Issue #2', 'Test Body', 'https://example.com/2', 'jwage', [], false); |
||
198 | $issue2->setLinkedPullRequest($pullRequest2); |
||
199 | |||
200 | $pullRequest1->setLinkedIssue($issue1); |
||
201 | $pullRequest2->setLinkedIssue($issue2); |
||
202 | |||
203 | $issueGroup = new IssueGroup('', [$pullRequest1]); |
||
|
|||
204 | $issueGroupNamed = new IssueGroup('Enhancement', [$pullRequest2]); |
||
205 | |||
206 | $milestoneIssues = [$issue1, $issue2, $pullRequest1, $pullRequest2]; |
||
207 | $issueGroups = [$issueGroup, $issueGroupNamed]; |
||
208 | |||
209 | $changelogConfig = (new ChangelogConfig($user, $repository, $milestone, [])) |
||
210 | ->setShowContributors(true); |
||
211 | |||
212 | $this->issueRepository->expects(self::once()) |
||
213 | ->method('getMilestoneIssues') |
||
214 | ->with($changelogConfig) |
||
215 | ->willReturn($milestoneIssues); |
||
216 | |||
217 | $this->issueGrouper->expects(self::once()) |
||
218 | ->method('groupIssues') |
||
219 | ->with($milestoneIssues) |
||
220 | ->willReturn($issueGroups); |
||
221 | |||
222 | $this->changelogGenerator->generate($changelogConfig, $output); |
||
223 | |||
224 | rewind($outputStream); |
||
225 | self::assertSame( |
||
226 | <<<'EXPECTED_OUTPUT' |
||
227 | 1.0 |
||
228 | === |
||
229 | |||
230 | - Total issues resolved: **2** |
||
231 | - Total pull requests resolved: **2** |
||
232 | - Total contributors: **3** |
||
233 | |||
234 | |||
235 | |||
236 | |||
237 | - [3: Issue #3](https://example.com/3) thanks to @Ocramius and @jwage |
||
238 | |||
239 | Enhancement |
||
240 | ----------- |
||
241 | |||
242 | - [4: Issue #4](https://example.com/4) thanks to @romanb and @jwage |
||
243 | |||
244 | Contributors |
||
245 | ------------ |
||
246 | |||
247 | - [@jwage](https://github.com/jwage) |
||
248 | - [@Ocramius](https://github.com/Ocramius) |
||
249 | - [@romanb](https://github.com/romanb) |
||
250 | |||
251 | |||
252 | EXPECTED_OUTPUT |
||
253 | , |
||
254 | stream_get_contents($outputStream) |
||
255 | ); |
||
269 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.