These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\ConfigBundle\DependencyInjection\Compiler; |
||
4 | |||
5 | use Exception; |
||
6 | use InvalidArgumentException; |
||
7 | use Kunstmaan\ConfigBundle\Entity\ConfigurationInterface; |
||
8 | use ReflectionException; |
||
9 | use RuntimeException; |
||
10 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
||
11 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
12 | |||
13 | /** |
||
14 | * @deprecated This class is deprecated in KunstmaanConfigBundle 5.3 and will be removed in KunstmaanConfigBundle 6.0. The entity validation is moved to the bundle configuration instead. |
||
15 | */ |
||
16 | class KunstmaanConfigConfigurationPass implements CompilerPassInterface |
||
17 | { |
||
18 | /** |
||
19 | * {@inheritdoc} |
||
20 | */ |
||
21 | public function process(ContainerBuilder $container) |
||
22 | { |
||
23 | try { |
||
24 | $backendConfiguration = $container->getParameter('kunstmaan_config'); |
||
25 | |||
26 | if (empty($backendConfiguration['entities'])) { |
||
27 | throw new \RuntimeException('You need to provide at least one config entity for this bundle to work.'); |
||
28 | } |
||
29 | |||
30 | // Check if entity exists. |
||
31 | foreach ($backendConfiguration['entities'] as $class) { |
||
32 | try { |
||
33 | $container->get('doctrine')->getManagerForClass($class); |
||
34 | } catch (ReflectionException $e) { |
||
35 | throw new InvalidArgumentException(sprintf('Entity "%s" does not exist', $class)); |
||
36 | } |
||
37 | |||
38 | // Check if entity implements the ConfigurationInterface. |
||
39 | View Code Duplication | if (!\in_array(ConfigurationInterface::class, class_implements($class))) { |
|
0 ignored issues
–
show
|
|||
40 | throw new RuntimeException(sprintf('The entity class "%s" needs to implement the ConfigurationInterface', $class)); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | return $backendConfiguration; |
||
45 | } catch (Exception $e) { |
||
46 | return []; |
||
47 | } |
||
48 | } |
||
49 | } |
||
50 |
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.