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 |
||
7 | class OpenGraphExtension extends atoum |
||
8 | { |
||
9 | public function testRenderNamespaceAttributesFunction() |
||
10 | { |
||
11 | $this |
||
12 | ->given( |
||
13 | $renderer = new \mock\Novaway\Component\OpenGraph\View\OpenGraphRendererInterface(), |
||
14 | $graph = new \mock\Novaway\Component\OpenGraph\OpenGraphInterface() |
||
15 | ) |
||
16 | ->if($this->newTestedInstance($renderer)) |
||
17 | ->then |
||
18 | ->given($this->testedInstance->renderNamespaceFunction($graph)) |
||
19 | ->mock($renderer) |
||
20 | ->call('renderNamespaceAttributes') |
||
21 | ->withAtLeastArguments([$graph])->once() |
||
22 | ; |
||
23 | } |
||
24 | |||
25 | public function testRenderGraphFunction() |
||
26 | { |
||
27 | $this |
||
28 | ->given( |
||
29 | $renderer = new \mock\Novaway\Component\OpenGraph\View\OpenGraphRendererInterface(), |
||
30 | $graph = new \mock\Novaway\Component\OpenGraph\OpenGraphInterface() |
||
31 | ) |
||
32 | ->if($this->newTestedInstance($renderer)) |
||
33 | ->then |
||
34 | ->given($this->testedInstance->renderGraphFunction($graph)) |
||
35 | ->mock($renderer) |
||
36 | ->call('render') |
||
37 | ->withAtLeastArguments([$graph])->once() |
||
38 | ; |
||
39 | } |
||
40 | |||
41 | public function testRenderTagFunction() |
||
42 | { |
||
43 | $this |
||
44 | ->given( |
||
45 | $renderer = new \mock\Novaway\Component\OpenGraph\View\OpenGraphRendererInterface(), |
||
46 | $tag = new \mock\Novaway\Component\OpenGraph\OpenGraphTagInterface() |
||
47 | ) |
||
48 | ->if($this->newTestedInstance($renderer)) |
||
49 | ->then |
||
50 | ->given($this->testedInstance->renderTagFunction($tag)) |
||
51 | ->mock($renderer) |
||
52 | ->call('renderTag') |
||
53 | ->withAtLeastArguments([$tag])->once() |
||
54 | ; |
||
55 | } |
||
56 | } |
||
57 | |||
58 |