Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
14 | class NoPeriodOnSubjectEndTest extends \PHPUnit_Framework_TestCase |
||
15 | { |
||
16 | /** |
||
17 | * Tests NoPeriodOnSubjectEnd::pass |
||
18 | */ |
||
19 | public function testPassSuccess() |
||
20 | { |
||
21 | $msg = new CommitMessage('Foo bar'); |
||
22 | $rule = new NoPeriodOnSubjectEnd(); |
||
23 | $this->assertTrue($rule->pass($msg)); |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * Tests NoPeriodOnSubjectEnd::pass |
||
28 | */ |
||
29 | public function testPassFail() |
||
30 | { |
||
31 | $msg = new CommitMessage('Foo bar.'); |
||
32 | $rule = new NoPeriodOnSubjectEnd(); |
||
33 | $this->assertFalse($rule->pass($msg)); |
||
34 | } |
||
35 | } |
||
36 |