Conditions | 12 |
Paths | 31 |
Total Lines | 63 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
33 | public function process(ContainerBuilder $container) |
||
34 | { |
||
35 | if (!$container->hasParameter('doctrine.entity_managers')) { |
||
36 | return; |
||
37 | } |
||
38 | |||
39 | $entityManagers = $container->getParameter('doctrine.entity_managers'); |
||
40 | $customRepositories = []; |
||
41 | |||
42 | foreach ($entityManagers as $name => $serviceName) { |
||
43 | $metadataDriverService = sprintf('doctrine.orm.%s_metadata_driver', $name); |
||
44 | |||
45 | if (!$container->has($metadataDriverService)) { |
||
46 | continue; |
||
47 | } |
||
48 | |||
49 | /** @var MappingDriver $metadataDriver */ |
||
50 | $metadataDriver = $container->get($metadataDriverService); |
||
51 | $entityClassNames = $metadataDriver->getAllClassNames(); |
||
52 | |||
53 | foreach ($entityClassNames as $entityClassName) { |
||
54 | $classMetadata = new ClassMetadata($entityClassName); |
||
55 | $metadataDriver->loadMetadataForClass($entityClassName, $classMetadata); |
||
56 | |||
57 | if ($classMetadata->customRepositoryClassName) { |
||
58 | $customRepositories[$classMetadata->customRepositoryClassName][] = [ |
||
59 | 0 => $entityClassName, |
||
60 | 1 => $name, |
||
61 | ]; |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 | |||
66 | foreach ($customRepositories as $repositoryClass => $entities) { |
||
67 | if ($container->has($repositoryClass)) { |
||
68 | continue; |
||
69 | } |
||
70 | |||
71 | if (count($entities) !== 1) { |
||
72 | $this->log($container, "Cannot auto-register repository \"".$repositoryClass."\": Entity belongs to multiple entity managers."); |
||
73 | continue; |
||
74 | } |
||
75 | |||
76 | if ($this->hasConflictingServices($container, $repositoryClass)) { |
||
77 | $this->log($container, "Cannot auto-register repository \"".$repositoryClass."\": There are already services for the repository class."); |
||
78 | continue; |
||
79 | |||
80 | } |
||
81 | |||
82 | $definition = $container->register($repositoryClass, $repositoryClass) |
||
83 | ->setFactory([new Reference('doctrine'), 'getRepository']) |
||
84 | ->setArguments($entities[0]) |
||
85 | ->setPublic(false) |
||
86 | ; |
||
87 | |||
88 | if (Kernel::MAJOR_VERSION <= 2 && Kernel::MINOR_VERSION <= 7) { |
||
89 | $definition->setScope('prototype'); |
||
|
|||
90 | } else { |
||
91 | $definition->setShared(false); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | } |
||
96 | |||
123 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.