| Conditions | 17 |
| Paths | 177 |
| Total Lines | 114 |
| Lines | 21 |
| Ratio | 18.42 % |
| 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 |
||
| 43 | public function collect(Request $request, Response $response, Throwable $exception = null) |
||
| 44 | { |
||
| 45 | parent::collect($request, $response, $exception); |
||
| 46 | |||
| 47 | $errors = []; |
||
| 48 | $entities = []; |
||
| 49 | $caches = [ |
||
| 50 | 'enabled' => false, |
||
| 51 | 'log_enabled' => false, |
||
| 52 | 'counts' => [ |
||
| 53 | 'puts' => 0, |
||
| 54 | 'hits' => 0, |
||
| 55 | 'misses' => 0, |
||
| 56 | ], |
||
| 57 | 'regions' => [ |
||
| 58 | 'puts' => [], |
||
| 59 | 'hits' => [], |
||
| 60 | 'misses' => [], |
||
| 61 | ], |
||
| 62 | ]; |
||
| 63 | |||
| 64 | /** @var EntityManager $em */ |
||
| 65 | foreach ($this->registry->getManagers() as $name => $em) { |
||
| 66 | if ($this->shouldValidateSchema) { |
||
| 67 | $entities[$name] = []; |
||
| 68 | |||
| 69 | /** @var ClassMetadataFactory $factory */ |
||
| 70 | $factory = $em->getMetadataFactory(); |
||
| 71 | $validator = new SchemaValidator($em); |
||
| 72 | |||
| 73 | /** @var ClassMetadataInfo $class */ |
||
| 74 | foreach ($factory->getLoadedMetadata() as $class) { |
||
| 75 | if (isset($entities[$name][$class->getName()])) { |
||
| 76 | continue; |
||
| 77 | } |
||
| 78 | |||
| 79 | $classErrors = $validator->validateClass($class); |
||
| 80 | $entities[$name][$class->getName()] = $class->getName(); |
||
| 81 | |||
| 82 | if (empty($classErrors)) { |
||
| 83 | continue; |
||
| 84 | } |
||
| 85 | |||
| 86 | $errors[$name][$class->getName()] = $classErrors; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | /** @var Configuration $emConfig */ |
||
| 91 | $emConfig = $em->getConfiguration(); |
||
| 92 | $slcEnabled = $emConfig->isSecondLevelCacheEnabled(); |
||
| 93 | |||
| 94 | if (! $slcEnabled) { |
||
| 95 | continue; |
||
| 96 | } |
||
| 97 | |||
| 98 | $caches['enabled'] = true; |
||
| 99 | |||
| 100 | /** @var $cacheConfiguration \Doctrine\ORM\Cache\CacheConfiguration */ |
||
| 101 | /** @var CacheLoggerChain $cacheLoggerChain */ |
||
| 102 | $cacheConfiguration = $emConfig->getSecondLevelCacheConfiguration(); |
||
| 103 | $cacheLoggerChain = $cacheConfiguration->getCacheLogger(); |
||
| 104 | |||
| 105 | if (! $cacheLoggerChain || ! $cacheLoggerChain->getLogger('statistics')) { |
||
| 106 | continue; |
||
| 107 | } |
||
| 108 | |||
| 109 | /** @var StatisticsCacheLogger $cacheLoggerStats */ |
||
| 110 | $cacheLoggerStats = $cacheLoggerChain->getLogger('statistics'); |
||
| 111 | $caches['log_enabled'] = true; |
||
| 112 | |||
| 113 | $caches['counts']['puts'] += $cacheLoggerStats->getPutCount(); |
||
| 114 | $caches['counts']['hits'] += $cacheLoggerStats->getHitCount(); |
||
| 115 | $caches['counts']['misses'] += $cacheLoggerStats->getMissCount(); |
||
| 116 | |||
| 117 | View Code Duplication | foreach ($cacheLoggerStats->getRegionsPut() as $key => $value) { |
|
| 118 | if (! isset($caches['regions']['puts'][$key])) { |
||
| 119 | $caches['regions']['puts'][$key] = 0; |
||
| 120 | } |
||
| 121 | |||
| 122 | $caches['regions']['puts'][$key] += $value; |
||
| 123 | } |
||
| 124 | |||
| 125 | View Code Duplication | foreach ($cacheLoggerStats->getRegionsHit() as $key => $value) { |
|
| 126 | if (! isset($caches['regions']['hits'][$key])) { |
||
| 127 | $caches['regions']['hits'][$key] = 0; |
||
| 128 | } |
||
| 129 | |||
| 130 | $caches['regions']['hits'][$key] += $value; |
||
| 131 | } |
||
| 132 | |||
| 133 | View Code Duplication | foreach ($cacheLoggerStats->getRegionsMiss() as $key => $value) { |
|
| 134 | if (! isset($caches['regions']['misses'][$key])) { |
||
| 135 | $caches['regions']['misses'][$key] = 0; |
||
| 136 | } |
||
| 137 | |||
| 138 | $caches['regions']['misses'][$key] += $value; |
||
| 139 | } |
||
| 140 | } |
||
| 141 | |||
| 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 | // To be removed when the required minimum version of symfony/doctrine-bridge is >= 4.4 |
||
| 148 | $query['runnable'] = $query['runnable'] ?? true; |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | $this->data['entities'] = $entities; |
||
| 153 | $this->data['errors'] = $errors; |
||
| 154 | $this->data['caches'] = $caches; |
||
| 155 | $this->groupedQueries = null; |
||
| 156 | } |
||
| 157 | |||
| 268 |