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