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 |
||
17 | class BasicSeoConfiguratorTest extends TestCase |
||
18 | { |
||
19 | /** |
||
20 | * @var BasicSeoGenerator |
||
21 | */ |
||
22 | protected $generator; |
||
23 | |||
24 | protected function setUp() |
||
28 | |||
29 | /** |
||
30 | * @expectedException \Leogout\Bundle\SeoBundle\Exception\InvalidSeoGeneratorException |
||
31 | * @expectedExceptionMessage Invalid seo generator passed to Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoConfigurator. Expected "Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoGenerator", but got "Leogout\Bundle\SeoBundle\Seo\Twitter\TwitterSeoGenerator". |
||
32 | */ |
||
33 | public function testException() |
||
39 | |||
40 | View Code Duplication | public function testTitle() |
|
|
|||
41 | { |
||
42 | $config = [ |
||
43 | 'title' => 'Awesome | Site' |
||
44 | ]; |
||
45 | |||
46 | $configurator = new BasicSeoConfigurator($config); |
||
47 | $configurator->configure($this->generator); |
||
48 | |||
49 | $this->assertEquals( |
||
50 | '<title>Awesome | Site</title>', |
||
51 | $this->generator->render() |
||
52 | ); |
||
53 | } |
||
54 | |||
55 | View Code Duplication | public function testDescription() |
|
56 | { |
||
57 | $config = [ |
||
58 | 'description' => 'My awesome site is so cool!', |
||
59 | ]; |
||
60 | |||
61 | $configurator = new BasicSeoConfigurator($config); |
||
62 | $configurator->configure($this->generator); |
||
63 | |||
64 | $this->assertEquals( |
||
65 | '<meta name="description" content="My awesome site is so cool!" />', |
||
66 | $this->generator->render() |
||
67 | ); |
||
68 | } |
||
69 | |||
70 | View Code Duplication | public function testKeywords() |
|
84 | |||
85 | View Code Duplication | public function testCanonical() |
|
86 | { |
||
99 | |||
100 | public function testRobots() |
||
117 | |||
118 | View Code Duplication | public function testNoConfig() |
|
130 | } |
||
131 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.