| Conditions | 18 |
| Paths | 242 |
| Total Lines | 110 |
| Code Lines | 60 |
| Lines | 21 |
| Ratio | 19.09 % |
| 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 |
||
| 45 | public function collect(Request $request, Response $response, \Exception $exception = null) |
||
| 46 | { |
||
| 47 | parent::collect($request, $response, $exception); |
||
| 48 | |||
| 49 | $errors = array(); |
||
| 50 | $entities = array(); |
||
| 51 | $caches = array( |
||
| 52 | 'enabled' => false, |
||
| 53 | 'log_enabled' => false, |
||
| 54 | 'counts' => array( |
||
| 55 | 'puts' => 0, |
||
| 56 | 'hits' => 0, |
||
| 57 | 'misses' => 0, |
||
| 58 | ), |
||
| 59 | 'regions' => array( |
||
| 60 | 'puts' => array(), |
||
| 61 | 'hits' => array(), |
||
| 62 | 'misses' => array(), |
||
| 63 | ), |
||
| 64 | ); |
||
| 65 | |||
| 66 | foreach ($this->registry->getManagers() as $name => $em) { |
||
| 67 | $entities[$name] = array(); |
||
| 68 | /** @var $factory \Doctrine\ORM\Mapping\ClassMetadataFactory */ |
||
| 69 | $factory = $em->getMetadataFactory(); |
||
| 70 | $validator = new SchemaValidator($em); |
||
| 71 | |||
| 72 | /** @var $class \Doctrine\ORM\Mapping\ClassMetadataInfo */ |
||
| 73 | foreach ($factory->getLoadedMetadata() as $class) { |
||
| 74 | if (!isset($entities[$name][$class->getName()])) { |
||
| 75 | $classErrors = $validator->validateClass($class); |
||
| 76 | $entities[$name][$class->getName()] = $class->getName(); |
||
| 77 | |||
| 78 | if (!empty($classErrors)) { |
||
| 79 | $errors[$name][$class->getName()] = $classErrors; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { |
||
| 85 | continue; |
||
| 86 | } |
||
| 87 | |||
| 88 | /** @var $emConfig \Doctrine\ORM\Configuration */ |
||
| 89 | $emConfig = $em->getConfiguration(); |
||
| 90 | $slcEnabled = $emConfig->isSecondLevelCacheEnabled(); |
||
| 91 | |||
| 92 | if (!$slcEnabled) { |
||
| 93 | continue; |
||
| 94 | } |
||
| 95 | |||
| 96 | $caches['enabled'] = true; |
||
| 97 | |||
| 98 | /** @var $cacheConfiguration \Doctrine\ORM\Cache\CacheConfiguration */ |
||
| 99 | /** @var $cacheLoggerChain \Doctrine\ORM\Cache\Logging\CacheLoggerChain */ |
||
| 100 | $cacheConfiguration = $emConfig->getSecondLevelCacheConfiguration(); |
||
| 101 | $cacheLoggerChain = $cacheConfiguration->getCacheLogger(); |
||
| 102 | |||
| 103 | if (!$cacheLoggerChain || !$cacheLoggerChain->getLogger('statistics')) { |
||
| 104 | continue; |
||
| 105 | } |
||
| 106 | |||
| 107 | /** @var $cacheLoggerStats \Doctrine\ORM\Cache\Logging\StatisticsCacheLogger */ |
||
| 108 | $cacheLoggerStats = $cacheLoggerChain->getLogger('statistics'); |
||
| 109 | $caches['log_enabled'] = true; |
||
| 110 | |||
| 111 | $caches['counts']['puts'] += $cacheLoggerStats->getPutCount(); |
||
| 112 | $caches['counts']['hits'] += $cacheLoggerStats->getHitCount(); |
||
| 113 | $caches['counts']['misses'] += $cacheLoggerStats->getMissCount(); |
||
| 114 | |||
| 115 | View Code Duplication | foreach ($cacheLoggerStats->getRegionsPut() as $key => $value) { |
|
| 116 | if (!isset($caches['regions']['puts'][$key])) { |
||
| 117 | $caches['regions']['puts'][$key] = 0; |
||
| 118 | } |
||
| 119 | |||
| 120 | $caches['regions']['puts'][$key] += $value; |
||
| 121 | } |
||
| 122 | |||
| 123 | View Code Duplication | foreach ($cacheLoggerStats->getRegionsHit() as $key => $value) { |
|
| 124 | if (!isset($caches['regions']['hits'][$key])) { |
||
| 125 | $caches['regions']['hits'][$key] = 0; |
||
| 126 | } |
||
| 127 | |||
| 128 | $caches['regions']['hits'][$key] += $value; |
||
| 129 | } |
||
| 130 | |||
| 131 | View Code Duplication | foreach ($cacheLoggerStats->getRegionsMiss() as $key => $value) { |
|
| 132 | if (!isset($caches['regions']['misses'][$key])) { |
||
| 133 | $caches['regions']['misses'][$key] = 0; |
||
| 134 | } |
||
| 135 | |||
| 136 | $caches['regions']['misses'][$key] += $value; |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | // HttpKernel < 3.2 compatibility layer |
||
| 141 | if (method_exists($this, 'cloneVar')) { |
||
| 142 | // Might be good idea to replicate this block in doctrine bridge so we can drop this from here after some time. |
||
| 143 | // This code is compatible with such change, because cloneVar is supposed to check if input is already cloned. |
||
| 144 | foreach ($this->data['queries'] as &$queries) { |
||
| 145 | foreach ($queries as &$query) { |
||
| 146 | $query['params'] = $this->cloneVar($query['params']); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | $this->data['entities'] = $entities; |
||
| 152 | $this->data['errors'] = $errors; |
||
| 153 | $this->data['caches'] = $caches; |
||
| 154 | } |
||
| 155 | |||
| 267 |