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 CriteriaBuilderCompilerPass extends AbstractContextCompilerPass |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * {@inheritdoc} |
||
| 16 | */ |
||
| 17 | 3 | protected function processParam( |
|
| 18 | $contextId, |
||
| 19 | array &$paramConfig, |
||
| 20 | ContainerBuilder $container |
||
| 21 | ) { |
||
| 22 | 3 | foreach ($paramConfig['builders'] as &$builder) { |
|
| 23 | 3 | $definitionName = $this->processCriteriaBuilder($contextId, $builder, $container); |
|
| 24 | |||
| 25 | $criteriaCollection = $this |
||
| 26 | 3 | ->buildServiceName($contextId, self::BUILDER_COLLECTION_PARAMETER); |
|
| 27 | $container |
||
| 28 | 3 | ->getDefinition($criteriaCollection) |
|
| 29 | 3 | ->addMethodCall( |
|
| 30 | 3 | 'addCriteriaBuilder', |
|
| 31 | 3 | [new Reference($definitionName)] |
|
| 32 | ); |
||
| 33 | } |
||
| 34 | 3 | } |
|
| 35 | |||
| 36 | /** |
||
| 37 | * @param string $contextId |
||
| 38 | * @param array $builder |
||
| 39 | * @param ContainerBuilder $container |
||
| 40 | * |
||
| 41 | * @return string |
||
| 42 | * |
||
| 43 | * @throws InvalidDefinitionException |
||
| 44 | */ |
||
| 45 | 3 | View Code Duplication | private function processCriteriaBuilder( |
| 59 | } |
||
| 60 |