Conditions | 14 |
Paths | 91 |
Total Lines | 71 |
Code Lines | 40 |
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 |
||
18 | public function process(ContainerBuilder $container) |
||
19 | { |
||
20 | if (!$container->hasParameter('doctrine.entity_managers')) { |
||
21 | return; |
||
22 | } |
||
23 | |||
24 | $entityManagers = $container->getParameter('doctrine.entity_managers'); |
||
25 | $customRepositories = []; |
||
26 | |||
27 | foreach ($entityManagers as $name => $serviceName) { |
||
28 | $metadataDriverService = sprintf('doctrine.orm.%s_metadata_driver', $name); |
||
29 | |||
30 | if (!$container->has($metadataDriverService)) { |
||
31 | continue; |
||
32 | } |
||
33 | |||
34 | /** @var MappingDriver $metadataDriver */ |
||
35 | $metadataDriver = $container->get($metadataDriverService); |
||
36 | $entityClassNames = $metadataDriver->getAllClassNames(); |
||
37 | |||
38 | foreach ($entityClassNames as $entityClassName) { |
||
39 | $classMetadata = new ClassMetadata($entityClassName); |
||
40 | $metadataDriver->loadMetadataForClass($entityClassName, $classMetadata); |
||
41 | |||
42 | if ($classMetadata->customRepositoryClassName) { |
||
43 | $customRepositories[$classMetadata->customRepositoryClassName][] = [ |
||
44 | 0 => $entityClassName, |
||
45 | 1 => $name, |
||
46 | ]; |
||
47 | } |
||
48 | } |
||
49 | } |
||
50 | |||
51 | $rootConflicts = []; |
||
52 | foreach ($customRepositories as $repositoryClass => $entities) { |
||
53 | $repoConflicts = $this->findConflictingServices($container, $repositoryClass); |
||
54 | |||
55 | if (count($repoConflicts)) { |
||
56 | $rootConflicts[$repositoryClass] = $repoConflicts; |
||
57 | } |
||
58 | } |
||
59 | |||
60 | foreach ($customRepositories as $repositoryClass => $entities) { |
||
61 | if ($container->has($repositoryClass)) { |
||
62 | continue; |
||
63 | } |
||
64 | |||
65 | if (count($entities) !== 1) { |
||
66 | $this->log($container, "Cannot auto-register repository \"".$repositoryClass."\": Entity belongs to multiple entity managers."); |
||
67 | continue; |
||
68 | } |
||
69 | |||
70 | if (isset($rootConflicts[$repositoryClass])) { |
||
71 | $this->log($container, "Cannot auto-register repository \"".$repositoryClass."\": There are already services for the repository class."); |
||
72 | continue; |
||
73 | } |
||
74 | |||
75 | $definition = $container->register($repositoryClass, $repositoryClass) |
||
76 | ->setFactory([new Reference('doctrine'), 'getRepository']) |
||
77 | ->setArguments($entities[0]) |
||
78 | ->setPublic(false) |
||
79 | ; |
||
80 | |||
81 | if (Kernel::MAJOR_VERSION <= 2 && Kernel::MINOR_VERSION <= 7) { |
||
82 | $definition->setScope('prototype'); |
||
|
|||
83 | } else { |
||
84 | $definition->setShared(false); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | } |
||
89 | |||
119 |
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.