Conditions | 5 |
Paths | 2 |
Total Lines | 39 |
Lines | 3 |
Ratio | 7.69 % |
Changes | 0 |
1 | <?php |
||
19 | public function getConfigTreeBuilder() |
||
20 | { |
||
21 | $treeBuilder = new TreeBuilder('kunstmaan_config'); |
||
22 | if (method_exists($treeBuilder, 'getRootNode')) { |
||
23 | $rootNode = $treeBuilder->getRootNode(); |
||
24 | } else { |
||
25 | // BC layer for symfony/config 4.1 and older |
||
26 | $rootNode = $treeBuilder->root('kunstmaan_config'); |
||
27 | } |
||
28 | |||
29 | $rootNode |
||
30 | ->children() |
||
31 | ->arrayNode('entities') |
||
32 | ->defaultValue([]) |
||
33 | ->normalizeKeys(false) |
||
34 | ->info('The list of entities to manage in the settings zone') |
||
35 | ->prototype('scalar')->end() |
||
36 | ->beforeNormalization() |
||
37 | ->always() |
||
38 | ->then(function ($entities) { |
||
39 | foreach ($entities as $entity) { |
||
40 | if (!class_exists($entity)) { |
||
41 | throw new \InvalidArgumentException(sprintf('Entity "%s" does not exist', $entity)); |
||
42 | } |
||
43 | |||
44 | // Check if entity implements the ConfigurationInterface. |
||
45 | View Code Duplication | if (!in_array(KunstmaanConfigurationInterface::class, class_implements($entity))) { |
|
|
|||
46 | throw new \RuntimeException(sprintf('The entity class "%s" needs to implement the %s', $entity, KunstmaanConfigurationInterface::class)); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | return $entities; |
||
51 | }) |
||
52 | ->end() |
||
53 | ->end() |
||
54 | ->end(); |
||
55 | |||
56 | return $treeBuilder; |
||
57 | } |
||
58 | } |
||
59 |
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.