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 |
||
19 | final class TranslationBlockTest extends BaseTwigVisitorTest |
||
20 | { |
||
21 | public function testTrans() |
||
22 | { |
||
23 | $collection = $this->getSourceLocations(TwigVisitorFactory::create(), 'Twig/TranslationBlock/trans.html.twig'); |
||
24 | |||
25 | $this->assertCount(3, $collection); |
||
26 | $source = $collection->get(0); |
||
27 | $this->assertEquals('foobar', $source->getMessage()); |
||
28 | $this->assertEquals('domain', $source->getContext()['domain']); |
||
29 | |||
30 | $source = $collection->get(1); |
||
31 | $this->assertEquals('no-domain', $source->getMessage()); |
||
32 | $this->assertEquals('messages', $source->getContext()['domain']); |
||
33 | |||
34 | $source = $collection->get(2); |
||
35 | $this->assertEquals('trans-count', $source->getMessage()); |
||
36 | $this->assertEquals('messages', $source->getContext()['domain']); |
||
37 | } |
||
38 | |||
39 | public function testTranschoice() |
||
40 | { |
||
41 | $collection = $this->getSourceLocations(TwigVisitorFactory::create(), 'Twig/TranslationBlock/transchoice.html.twig'); |
||
42 | |||
43 | $this->assertCount(1, $collection); |
||
44 | $source = $collection->first(); |
||
45 | $this->assertEquals('foobar', $source->getMessage()); |
||
46 | } |
||
47 | } |
||
48 |