| Conditions | 12 |
| Paths | 60 |
| Total Lines | 95 |
| Code Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 1 | 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 |
||
| 31 | public function register(Container $container) |
||
| 32 | { |
||
| 33 | $container['doctrine'] = function ($container) { |
||
| 34 | return new ManagerRegistry($container); |
||
| 35 | }; |
||
| 36 | |||
| 37 | if (!isset($container['orm.ems.factory'])) { |
||
| 38 | $container['orm.ems.factory'] = function (Container $container) { |
||
| 39 | $container['orm.ems.options.initializer'](); |
||
| 40 | $factory = new Container(); |
||
| 41 | foreach ($container['orm.ems.options'] as $name => $options) { |
||
| 42 | if ($container['orm.ems.default'] === $name) { |
||
| 43 | // we use shortcuts here in case the default has been overridden |
||
| 44 | $config = $container['orm.em.config']; |
||
| 45 | } else { |
||
| 46 | $config = $container['orm.ems.config'][$name]; |
||
| 47 | } |
||
| 48 | $factory[$name] = $factory->protect( |
||
| 49 | function () use ($container, $options, $config) { |
||
| 50 | return EntityManager::create( |
||
| 51 | $container['dbs'][$options['connection']], |
||
| 52 | $config, |
||
| 53 | $container['dbs.event_manager'][$options['connection']] |
||
| 54 | ); |
||
| 55 | } |
||
| 56 | ); |
||
| 57 | } |
||
| 58 | return $factory; |
||
| 59 | }; |
||
| 60 | } |
||
| 61 | |||
| 62 | |||
| 63 | if (isset($container['form.extensions']) && class_exists('Symfony\\Bridge\\Doctrine\\Form\\DoctrineOrmExtension')) { |
||
| 64 | $container['form.extensions'] = $container->extend('form.extensions', function ($extensions, $container) { |
||
| 65 | $extensions[] = new DoctrineOrmExtension($container['doctrine']); |
||
| 66 | |||
| 67 | return $extensions; |
||
| 68 | }); |
||
| 69 | } |
||
| 70 | |||
| 71 | if (isset($container['validator']) && class_exists('Symfony\\Bridge\\Doctrine\\Validator\\Constraints\\UniqueEntityValidator')) { |
||
| 72 | $container['doctrine.orm.validator.unique_validator'] = function ($container) { |
||
| 73 | return new UniqueEntityValidator($container['doctrine']); |
||
| 74 | }; |
||
| 75 | |||
| 76 | if (!isset($container['validator.validator_service_ids'])) { |
||
| 77 | $container['validator.validator_service_ids'] = array(); |
||
| 78 | } |
||
| 79 | |||
| 80 | $container['validator.validator_service_ids'] = array_merge( |
||
| 81 | $container['validator.validator_service_ids'], |
||
| 82 | array('doctrine.orm.validator.unique' => 'doctrine.orm.validator.unique_validator') |
||
| 83 | ); |
||
| 84 | |||
| 85 | $container['validator.object_initializers'] = $container->extend('validator.object_initializers', |
||
| 86 | function (array $objectInitializers) use ($container) { |
||
| 87 | $objectInitializers[] = new DoctrineInitializer($container['doctrine']); |
||
| 88 | |||
| 89 | return $objectInitializers; |
||
| 90 | } |
||
| 91 | ); |
||
| 92 | } |
||
| 93 | |||
| 94 | if (class_exists('Saxulum\\DoctrineOrmCommands\\Command\\CreateDatabaseDoctrineCommand')) { |
||
| 95 | if (isset($container['console'])) { |
||
| 96 | $container['console'] = $container->extend('console', function (ConsoleApplication $consoleApplication) use ($container) { |
||
| 97 | $helperSet = $consoleApplication->getHelperSet(); |
||
| 98 | $helperSet->set(new ManagerRegistryHelper($container['doctrine']), 'doctrine'); |
||
| 99 | |||
| 100 | return $consoleApplication; |
||
| 101 | }); |
||
| 102 | } |
||
| 103 | |||
| 104 | if (isset($container['console.commands'])) { |
||
| 105 | $container['console.commands'] = $container->extend('console.commands', function ($commands) use ($container) { |
||
| 106 | $commands[] = new CreateDatabaseDoctrineCommand; |
||
| 107 | $commands[] = new DropDatabaseDoctrineCommand; |
||
| 108 | $commands[] = new CreateSchemaDoctrineCommand; |
||
| 109 | $commands[] = new UpdateSchemaDoctrineCommand; |
||
| 110 | $commands[] = new DropSchemaDoctrineCommand; |
||
| 111 | $commands[] = new RunDqlDoctrineCommand; |
||
| 112 | $commands[] = new RunSqlDoctrineCommand; |
||
| 113 | $commands[] = new ConvertMappingDoctrineCommand; |
||
| 114 | $commands[] = new ClearMetadataCacheDoctrineCommand; |
||
| 115 | $commands[] = new ClearQueryCacheDoctrineCommand; |
||
| 116 | $commands[] = new ClearResultCacheDoctrineCommand; |
||
| 117 | $commands[] = new InfoDoctrineCommand; |
||
| 118 | $commands[] = new ValidateSchemaCommand; |
||
| 119 | $commands[] = new EnsureProductionSettingsDoctrineCommand; |
||
| 120 | |||
| 121 | return $commands; |
||
| 122 | }); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } |
||
| 126 | } |
||
| 127 |