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 |
||
| 12 | class FiltersCompilerPassTest extends \PHPUnit_Framework_TestCase |
||
| 13 | { |
||
| 14 | public function testProcess() |
||
| 15 | { |
||
| 16 | $managerDefinition = new Definition(); |
||
| 17 | $loaderDefinition = new Definition(); |
||
| 18 | $loaderDefinition->addTag('liip_imagine.filter.loader', array( |
||
| 19 | 'loader' => 'foo', |
||
| 20 | )); |
||
| 21 | |||
| 22 | $container = new ContainerBuilder(); |
||
| 23 | $container->setDefinition('liip_imagine.filter.manager', $managerDefinition); |
||
| 24 | $container->setDefinition('a.loader', $loaderDefinition); |
||
| 25 | |||
| 26 | $pass = new FiltersCompilerPass(); |
||
| 27 | |||
| 28 | //guard |
||
| 29 | $this->assertCount(0, $managerDefinition->getMethodCalls()); |
||
| 30 | |||
| 31 | $pass->process($container); |
||
| 32 | |||
| 33 | $this->assertCount(1, $managerDefinition->getMethodCalls()); |
||
| 34 | } |
||
| 35 | } |
||
| 36 |