Conditions | 5 |
Paths | 6 |
Total Lines | 37 |
Code Lines | 21 |
Lines | 14 |
Ratio | 37.84 % |
Changes | 0 |
1 | <?php |
||
11 | public function process(ContainerBuilder $container) |
||
12 | { |
||
13 | if (!$container->hasDefinition('psi_description.schema')) { |
||
14 | return; |
||
15 | } |
||
16 | |||
17 | $schemaDef = $container->getDefinition('psi_description.schema'); |
||
18 | $extensionIds = $container->findTaggedServiceIds('psi_description.schema_extension'); |
||
19 | |||
20 | $extensionRefs = []; |
||
21 | View Code Duplication | foreach ($extensionIds as $extensionId => $attributes) { |
|
|
|||
22 | $attributes = $attributes[0]; |
||
23 | |||
24 | if (!isset($attributes['alias'])) { |
||
25 | throw new \InvalidArgumentException(sprintf( |
||
26 | 'Description schema extension "%s" has no "alias" attribute in its tag', |
||
27 | $extensionId |
||
28 | )); |
||
29 | } |
||
30 | |||
31 | $alias = $attributes['alias']; |
||
32 | |||
33 | $extensionRefs[$alias] = new Reference($extensionId); |
||
34 | } |
||
35 | |||
36 | $enabledEnhancers = $container->getParameter('psi_description.schema.extensions'); |
||
37 | $diff = array_diff($enabledEnhancers, array_keys($extensionRefs)); |
||
38 | |||
39 | if ($diff) { |
||
40 | throw new \InvalidArgumentException(sprintf( |
||
41 | 'Unknown schema extension(s) "%s" specified. Known extensions: "%s"', |
||
42 | implode('", "', $diff), implode('", "', array_keys($extensionRefs)) |
||
43 | )); |
||
44 | } |
||
45 | |||
46 | $schemaDef->replaceArgument(0, array_values($extensionRefs)); |
||
47 | } |
||
48 | } |
||
49 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.