| Conditions | 9 |
| Paths | 15 |
| Total Lines | 51 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
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 |
||
| 17 | public function process(ContainerBuilder $container) |
||
| 18 | { |
||
| 19 | if (!$container->hasParameter('doctrine.entity_managers')) { |
||
| 20 | return; |
||
| 21 | } |
||
| 22 | |||
| 23 | $entityManagers = $container->getParameter('doctrine.entity_managers'); |
||
| 24 | $customRepositories = []; |
||
| 25 | |||
| 26 | foreach ($entityManagers as $name => $serviceName) { |
||
| 27 | $metadataDriverService = sprintf('doctrine.orm.%s_metadata_driver', $name); |
||
| 28 | |||
| 29 | if (!$container->has($metadataDriverService)) { |
||
| 30 | continue; |
||
| 31 | } |
||
| 32 | |||
| 33 | /** @var MappingDriver $metadataDriver */ |
||
| 34 | $metadataDriver = $container->get($metadataDriverService); |
||
| 35 | $entityClassNames = $metadataDriver->getAllClassNames(); |
||
| 36 | |||
| 37 | foreach ($entityClassNames as $entityClassName) { |
||
| 38 | $classMetadata = new ClassMetadata($entityClassName); |
||
| 39 | $metadataDriver->loadMetadataForClass($entityClassName, $classMetadata); |
||
| 40 | |||
| 41 | if ($classMetadata->customRepositoryClassName) { |
||
| 42 | $customRepositories[$classMetadata->customRepositoryClassName][] = [ |
||
| 43 | 0 => $entityClassName, |
||
| 44 | 1 => $name, |
||
| 45 | ]; |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | foreach ($customRepositories as $repositoryClass => $entities) { |
||
| 50 | if ($container->has($repositoryClass)) { |
||
| 51 | continue; |
||
| 52 | } |
||
| 53 | |||
| 54 | if (count($entities) === 1) { |
||
| 55 | $definition = new Definition($repositoryClass); |
||
| 56 | $definition->setFactory(array( |
||
| 57 | new Reference('doctrine'), |
||
| 58 | 'getRepository' |
||
| 59 | )); |
||
| 60 | $definition->setArguments($entities[0]); |
||
| 61 | $definition->setShared(false); |
||
| 62 | |||
| 63 | $container->setDefinition($repositoryClass, $definition); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | } |
||
| 67 | } |
||
| 68 | } |
||
| 69 |