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 |
||
6 | class YouTubeShortCodeHandlerTest extends SapphireTest |
||
7 | { |
||
8 | protected static $fixture_file = 'YouTubeShortCodeTest.yml'; |
||
9 | |||
10 | 1 | public function testVideoIdOnly() { |
|
19 | |||
20 | 1 | View Code Duplication | public function testVideoWithCaption() { |
21 | 1 | $page = $this->objFromFixture('Page', 'VideoWithCaption'); |
|
22 | 1 | $html = ShortcodeParser::get_active()->parse($page->Content); |
|
23 | 1 | $this->assertContains('<div class="YouTube">', $html); |
|
24 | $expected = '<iframe width="560" height="315" src="https://www.youtube' |
||
25 | . '.com/embed/5XQwWATPReA" frameborder="0" allowfullscreen=""' |
||
26 | 1 | . '></iframe>'; |
|
27 | 1 | $this->assertContains('<p>This is a caption</p>', $html); |
|
28 | |||
29 | 1 | $this->assertContains($expected, $html); |
|
30 | 1 | } |
|
31 | |||
32 | 1 | public function testVideoWithWidth() { |
|
41 | |||
42 | 1 | public function testVideoWithHeight() { |
|
51 | |||
52 | 1 | View Code Duplication | public function testVideoWithAll() { |
53 | 1 | $page = $this->objFromFixture('Page', 'VideoWithAll'); |
|
54 | 1 | $html = ShortcodeParser::get_active()->parse($page->Content); |
|
55 | 1 | $this->assertContains('<div class="YouTube">', $html); |
|
56 | $expected = '<iframe width="314" height="418" src="https://www.youtube' |
||
57 | . '.com/embed/5XQwWATPReA" frameborder="0" allowfullscreen=""' |
||
58 | 1 | . '></iframe>'; |
|
59 | 1 | $this->assertContains($expected, $html); |
|
60 | 1 | $this->assertContains('<p>This is a caption</p>', $html); |
|
61 | 1 | } |
|
62 | |||
63 | 1 | public function testVideoWithNoID() { |
|
69 | |||
70 | 1 | public function testVideoWithNoAutoPlay() { |
|
79 | } |
||
80 |