| Conditions | 7 |
| Paths | 13 |
| Total Lines | 67 |
| Code Lines | 40 |
| 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 namespace Comodojo\Extender\Components; |
||
| 66 | public function getEntityManager() { |
||
| 67 | |||
| 68 | if ( $this->entity_manager === null ) { |
||
| 69 | |||
| 70 | $configuration = $this->getConfiguration(); |
||
| 71 | |||
| 72 | $base_folder = $configuration->get('base-path'); |
||
| 73 | $connection_params = self::getConnectionParameters($configuration); |
||
| 74 | $entity_repositories = self::getEntityRepositories($configuration); |
||
| 75 | $proxies_folder = self::getProxiesFolder($configuration); |
||
| 76 | $devmode = (bool) $configuration->get('database-devmode'); |
||
| 77 | $metadata_mode = $configuration->get('database-metadata'); |
||
| 78 | $database_cache = $configuration->get('database-cache'); |
||
| 79 | |||
| 80 | $config_args = [ |
||
| 81 | $entity_repositories, |
||
| 82 | $devmode, |
||
| 83 | $proxies_folder, |
||
| 84 | null, |
||
| 85 | false |
||
| 86 | ]; |
||
| 87 | |||
| 88 | switch (strtoupper($metadata_mode)) { |
||
| 89 | |||
| 90 | case 'YAML': |
||
| 91 | $db_config = Setup::createYAMLMetadataConfiguration(...$config_args); |
||
| 92 | break; |
||
| 93 | |||
| 94 | case 'XML': |
||
| 95 | $db_config = Setup::createXMLMetadataConfiguration(...$config_args); |
||
| 96 | break; |
||
| 97 | |||
| 98 | case 'ANNOTATIONS': |
||
| 99 | default: |
||
| 100 | $db_config = Setup::createAnnotationMetadataConfiguration(...$config_args); |
||
| 101 | break; |
||
| 102 | } |
||
| 103 | |||
| 104 | if ( $devmode === false ) { |
||
| 105 | |||
| 106 | $db_config->setAutoGenerateProxyClasses(false); |
||
| 107 | |||
| 108 | if ( |
||
| 109 | strcasecmp('apc', $database_cache) === 0 |
||
| 110 | // && php_sapi_name() !== 'cli' |
||
| 111 | ) { |
||
| 112 | $cache = new ApcCache(); |
||
| 113 | $db_config->setQueryCacheImpl($cache); |
||
| 114 | $db_config->setResultCacheImpl($cache); |
||
| 115 | $db_config->setMetadataCacheImpl($cache); |
||
| 116 | } |
||
| 117 | |||
| 118 | } else { |
||
| 119 | |||
| 120 | $db_config->setAutoGenerateProxyClasses(true); |
||
| 121 | |||
| 122 | } |
||
| 123 | |||
| 124 | $this->entity_manager = EntityManager::create($connection_params, $db_config); |
||
| 125 | |||
| 126 | } else { |
||
| 127 | |||
| 128 | $this->entity_manager->clear(); |
||
| 129 | |||
| 130 | } |
||
| 131 | |||
| 132 | return $this->entity_manager; |
||
| 133 | |||
| 203 |