| Conditions | 15 |
| Paths | 864 |
| Total Lines | 97 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 125 | protected function _getEntityManager( |
||
| 126 | Connection $connection = null, |
||
| 127 | MappingDriver $mappingDriver = null |
||
| 128 | ) |
||
| 129 | { |
||
| 130 | // NOTE: Functional tests use their own shared metadata cache, because |
||
| 131 | // the actual database platform used during execution has effect on some |
||
| 132 | // metadata mapping behaviors (like the choice of the ID generation). |
||
| 133 | if (is_null(self::$_metadataCacheImpl)) { |
||
| 134 | if (isset($GLOBALS['DOCTRINE_CACHE_IMPL'])) { |
||
| 135 | self::$_metadataCacheImpl = new $GLOBALS['DOCTRINE_CACHE_IMPL']; |
||
| 136 | } else { |
||
| 137 | self::$_metadataCacheImpl = new ArrayCache(); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | if (is_null(self::$_queryCacheImpl)) { |
||
| 142 | self::$_queryCacheImpl = new ArrayCache(); |
||
| 143 | } |
||
| 144 | |||
| 145 | $this->_sqlLoggerStack = new DebugStack(); |
||
| 146 | $this->_sqlLoggerStack->enabled = false; |
||
| 147 | |||
| 148 | //FIXME: two different configs! $conn and the created entity manager have |
||
| 149 | // different configs. |
||
| 150 | $config = new Configuration(); |
||
| 151 | $config->setMetadataCacheImpl(self::$_metadataCacheImpl); |
||
| 152 | $config->setQueryCacheImpl(self::$_queryCacheImpl); |
||
| 153 | $config->setProxyDir(__DIR__ . '/../../../Proxies'); |
||
| 154 | $config->setProxyNamespace('Doctrine\Tests\Proxies'); |
||
| 155 | |||
| 156 | if (null !== $this->resultCacheImpl) { |
||
| 157 | $config->setResultCacheImpl($this->resultCacheImpl); |
||
| 158 | } |
||
| 159 | |||
| 160 | $enableSecondLevelCache = getenv('ENABLE_SECOND_LEVEL_CACHE'); |
||
| 161 | |||
| 162 | if ($this->isSecondLevelCacheEnabled || $enableSecondLevelCache) { |
||
| 163 | |||
| 164 | $cacheConfig = new CacheConfiguration(); |
||
| 165 | $cache = $this->getSharedSecondLevelCacheDriverImpl(); |
||
| 166 | |||
| 167 | $regionConfig = $cacheConfig->getRegionsConfiguration(); |
||
| 168 | $regionConfig->setDefaultLifetime(static::DEFAULT_CACHE_REGION_LIFE_TIME); |
||
| 169 | $factory = new DefaultCacheFactory($regionConfig, $cache); |
||
| 170 | |||
| 171 | $this->secondLevelCacheFactory = $factory; |
||
| 172 | |||
| 173 | if ($this->isSecondLevelCacheLogEnabled) { |
||
| 174 | $this->secondLevelCacheLogger = new StatisticsCacheLogger(); |
||
| 175 | $cacheConfig->setCacheLogger($this->secondLevelCacheLogger); |
||
| 176 | } |
||
| 177 | |||
| 178 | $cacheConfig->setCacheFactory($factory); |
||
| 179 | $config->setSecondLevelCacheEnabled(true); |
||
| 180 | $config->setSecondLevelCacheConfiguration($cacheConfig); |
||
| 181 | |||
| 182 | $this->isSecondLevelCacheEnabled = true; |
||
| 183 | } |
||
| 184 | |||
| 185 | $config->setMetadataDriverImpl( |
||
| 186 | $mappingDriver ?? $config->newDefaultAnnotationDriver( |
||
| 187 | [ |
||
| 188 | realpath(__DIR__ . '/../../../Models/Cache'), |
||
| 189 | realpath(__DIR__ . '/../../../Models/GeoNames') |
||
| 190 | ], |
||
| 191 | true |
||
| 192 | ) |
||
| 193 | ); |
||
| 194 | |||
| 195 | $conn = $connection ?: static::$_sharedConn; |
||
| 196 | $conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack); |
||
| 197 | |||
| 198 | // get rid of more global state |
||
| 199 | $evm = $conn->getEventManager(); |
||
| 200 | foreach ($evm->getListeners() AS $event => $listeners) { |
||
| 201 | foreach ($listeners AS $listener) { |
||
| 202 | $evm->removeEventListener([$event], $listener); |
||
| 203 | } |
||
| 204 | } |
||
| 205 | |||
| 206 | if ($enableSecondLevelCache) { |
||
| 207 | $evm->addEventListener('loadClassMetadata', new CacheMetadataListener()); |
||
| 208 | } |
||
| 209 | |||
| 210 | if (isset($GLOBALS['db_event_subscribers'])) { |
||
| 211 | foreach (explode(",", $GLOBALS['db_event_subscribers']) AS $subscriberClass) { |
||
| 212 | $subscriberInstance = new $subscriberClass(); |
||
| 213 | $evm->addEventSubscriber($subscriberInstance); |
||
| 214 | } |
||
| 215 | } |
||
| 216 | |||
| 217 | if (isset($GLOBALS['debug_uow_listener'])) { |
||
| 218 | $evm->addEventListener(['onFlush'], new DebugUnitOfWorkListener()); |
||
| 219 | } |
||
| 220 | |||
| 221 | return EntityManager::create($conn, $config); |
||
| 222 | } |
||
| 376 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: