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 CriteriaCompilerPass 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[self::CRITERIA_PARAMETER] as &$criteria) { |
|
23 | 3 | $definitionName = $this->processCriteria($contextId, $criteria, $container); |
|
24 | |||
25 | $criteriaCollection = $this |
||
26 | 3 | ->buildServiceName($contextId, self::CRITERIA_COLLECTION_PARAMETER); |
|
27 | $container |
||
28 | 3 | ->getDefinition($criteriaCollection) |
|
29 | 3 | ->addMethodCall( |
|
30 | 3 | 'addNamedCriteria', |
|
31 | 3 | [$criteria[self::NAME_PARAMETER], new Reference($definitionName)] |
|
32 | ); |
||
33 | } |
||
34 | 3 | } |
|
35 | |||
36 | /** |
||
37 | * @param string $contextId |
||
38 | * @param array $criteria |
||
39 | * @param ContainerBuilder $container |
||
40 | * |
||
41 | * @return string |
||
42 | * |
||
43 | * @throws InvalidDefinitionException |
||
44 | */ |
||
45 | 3 | View Code Duplication | private function processCriteria( |
59 | } |
||
60 |