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 |
||
22 | class TransformerPass implements CompilerPassInterface |
||
23 | { |
||
24 | /** |
||
25 | * {@inheritDoc} |
||
26 | * |
||
27 | * @param ContainerBuilder $container Symfony Service container |
||
28 | * |
||
29 | * @return void |
||
30 | */ |
||
31 | 2 | public function process(ContainerBuilder $container) |
|
32 | { |
||
33 | // always first check if the primary service is defined |
||
34 | 2 | if (!$container->has('graviton.proxy.service.transformationhandler')) { |
|
35 | return; |
||
36 | } |
||
37 | |||
38 | 2 | $definition = $container->findDefinition( |
|
39 | 'graviton.proxy.service.transformationhandler' |
||
40 | 2 | ); |
|
41 | 2 | $this->registerTaggedTransformation( |
|
42 | 2 | $container, |
|
43 | 2 | $definition, |
|
44 | 2 | 'graviton.proxy.transformer.request', |
|
45 | 'addRequestTransformation' |
||
46 | 2 | ); |
|
47 | 2 | $this->registerTaggedTransformation( |
|
48 | 2 | $container, |
|
49 | 2 | $definition, |
|
50 | 2 | 'graviton.proxy.transformer.response', |
|
51 | 'addResponseTransformation' |
||
52 | 2 | ); |
|
53 | 2 | $this->registerTaggedTransformation( |
|
54 | 2 | $container, |
|
55 | 2 | $definition, |
|
56 | 2 | 'graviton.proxy.transformer.schema', |
|
57 | 'addSchemaTransformation' |
||
58 | 2 | ); |
|
59 | 2 | } |
|
60 | |||
61 | /** |
||
62 | * Adds the found services to the TransformationHandler |
||
63 | * |
||
64 | * @param ContainerBuilder $container Symfony Service Container |
||
65 | * @param Definition $definition Service the services shall be add to. |
||
66 | * @param string $tag Tag identifying the service to be added |
||
67 | * @param string $callable Name of the method to call to add the tagged service. |
||
68 | * |
||
69 | * @return void |
||
70 | */ |
||
71 | 2 | private function registerTaggedTransformation(ContainerBuilder $container, Definition $definition, $tag, $callable) |
|
88 | } |
||
89 |