| Conditions | 15 | 
| Paths | 864 | 
| Total Lines | 97 | 
| Code Lines | 51 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 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  | 
            ||
| 93 | protected function _getEntityManager(  | 
            ||
| 94 | Connection $connection = null,  | 
            ||
| 95 | MappingDriver $mappingDriver = null  | 
            ||
| 96 | )  | 
            ||
| 97 |     { | 
            ||
| 98 | // NOTE: Functional tests use their own shared metadata cache, because  | 
            ||
| 99 | // the actual database platform used during execution has effect on some  | 
            ||
| 100 | // metadata mapping behaviors (like the choice of the ID generation).  | 
            ||
| 101 |         if (is_null(self::$_metadataCacheImpl)) { | 
            ||
| 102 |             if (isset($GLOBALS['DOCTRINE_CACHE_IMPL'])) { | 
            ||
| 103 | self::$_metadataCacheImpl = new $GLOBALS['DOCTRINE_CACHE_IMPL'];  | 
            ||
| 104 |             } else { | 
            ||
| 105 | self::$_metadataCacheImpl = new ArrayCache();  | 
            ||
| 106 | }  | 
            ||
| 107 | }  | 
            ||
| 108 | |||
| 109 |         if (is_null(self::$_queryCacheImpl)) { | 
            ||
| 110 | self::$_queryCacheImpl = new ArrayCache();  | 
            ||
| 111 | }  | 
            ||
| 112 | |||
| 113 | $this->_sqlLoggerStack = new DebugStack();  | 
            ||
| 114 | $this->_sqlLoggerStack->enabled = false;  | 
            ||
| 115 | |||
| 116 | //FIXME: two different configs! $conn and the created entity manager have  | 
            ||
| 117 | // different configs.  | 
            ||
| 118 | $config = new Configuration();  | 
            ||
| 119 | $config->setMetadataCacheImpl(self::$_metadataCacheImpl);  | 
            ||
| 120 | $config->setQueryCacheImpl(self::$_queryCacheImpl);  | 
            ||
| 121 | $config->setProxyDir(__DIR__ . '/../../../../Proxies');  | 
            ||
| 122 |         $config->setProxyNamespace('Doctrine\Tests\Proxies'); | 
            ||
| 123 | |||
| 124 |         if (null !== $this->resultCacheImpl) { | 
            ||
| 125 | $config->setResultCacheImpl($this->resultCacheImpl);  | 
            ||
| 126 | }  | 
            ||
| 127 | |||
| 128 |         $enableSecondLevelCache = getenv('ENABLE_SECOND_LEVEL_CACHE'); | 
            ||
| 129 | |||
| 130 |         if ($this->isSecondLevelCacheEnabled || $enableSecondLevelCache) { | 
            ||
| 131 | |||
| 132 | $cacheConfig = new CacheConfiguration();  | 
            ||
| 133 | $cache = $this->getSharedSecondLevelCacheDriverImpl();  | 
            ||
| 134 | |||
| 135 | $regionConfig = $cacheConfig->getRegionsConfiguration();  | 
            ||
| 136 | $regionConfig->setDefaultLifetime(static::DEFAULT_CACHE_REGION_LIFE_TIME);  | 
            ||
| 137 | $factory = new DefaultCacheFactory($regionConfig, $cache);  | 
            ||
| 138 | |||
| 139 | $this->secondLevelCacheFactory = $factory;  | 
            ||
| 140 | |||
| 141 |             if ($this->isSecondLevelCacheLogEnabled) { | 
            ||
| 142 | $this->secondLevelCacheLogger = new StatisticsCacheLogger();  | 
            ||
| 143 | $cacheConfig->setCacheLogger($this->secondLevelCacheLogger);  | 
            ||
| 144 | }  | 
            ||
| 145 | |||
| 146 | $cacheConfig->setCacheFactory($factory);  | 
            ||
| 147 | $config->setSecondLevelCacheEnabled(true);  | 
            ||
| 148 | $config->setSecondLevelCacheConfiguration($cacheConfig);  | 
            ||
| 149 | |||
| 150 | $this->isSecondLevelCacheEnabled = true;  | 
            ||
| 151 | }  | 
            ||
| 152 | |||
| 153 | $config->setMetadataDriverImpl(  | 
            ||
| 154 | $mappingDriver ?? $config->newDefaultAnnotationDriver(  | 
            ||
| 155 | [  | 
            ||
| 156 | realpath(__DIR__ . '/../../../../Models/Cache'),  | 
            ||
| 157 | realpath(__DIR__ . '/../../../../Models/GeoNames')  | 
            ||
| 158 | ],  | 
            ||
| 159 | true  | 
            ||
| 160 | )  | 
            ||
| 161 | );  | 
            ||
| 162 | |||
| 163 | $conn = $connection ?: static::$_sharedConn;  | 
            ||
| 164 | $conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack);  | 
            ||
| 165 | |||
| 166 | // get rid of more global state  | 
            ||
| 167 | $evm = $conn->getEventManager();  | 
            ||
| 168 |         foreach ($evm->getListeners() AS $event => $listeners) { | 
            ||
| 169 |             foreach ($listeners AS $listener) { | 
            ||
| 170 | $evm->removeEventListener([$event], $listener);  | 
            ||
| 171 | }  | 
            ||
| 172 | }  | 
            ||
| 173 | |||
| 174 |         if ($enableSecondLevelCache) { | 
            ||
| 175 |             $evm->addEventListener('loadClassMetadata', new CacheMetadataListener()); | 
            ||
| 176 | }  | 
            ||
| 177 | |||
| 178 |         if (isset($GLOBALS['db_event_subscribers'])) { | 
            ||
| 179 |             foreach (explode(",", $GLOBALS['db_event_subscribers']) AS $subscriberClass) { | 
            ||
| 180 | $subscriberInstance = new $subscriberClass();  | 
            ||
| 181 | $evm->addEventSubscriber($subscriberInstance);  | 
            ||
| 182 | }  | 
            ||
| 183 | }  | 
            ||
| 184 | |||
| 185 |         if (isset($GLOBALS['debug_uow_listener'])) { | 
            ||
| 186 | $evm->addEventListener(['onFlush'], new DebugUnitOfWorkListener());  | 
            ||
| 187 | }  | 
            ||
| 188 | |||
| 189 | return EntityManager::create($conn, $config);  | 
            ||
| 190 | }  | 
            ||
| 192 |