Passed
Push — master ( c39fb6...9e9a0d )
by Rafael
04:42
created

CachedFixtureEntityManager   B

Complexity

Total Complexity 44

Size/Duplication

Total Lines 361
Duplicated Lines 0 %

Test Coverage

Coverage 29.52%

Importance

Changes 0
Metric Value
dl 0
loc 361
ccs 31
cts 105
cp 0.2952
rs 8.3396
c 0
b 0
f 0
wmc 44

44 Methods

Rating   Name   Duplication   Size   Complexity  
A getExpressionBuilder() 0 3 1
A newHydrator() 0 3 1
A getEventManager() 0 3 1
A createNativeQuery() 0 3 1
A find() 0 3 1
A flushReal() 0 3 1
A hasFilters() 0 3 1
A copy() 0 3 1
A getPartialReference() 0 3 1
A detach() 0 3 1
A rollback() 0 3 1
A transactional() 0 4 1
A beginTransaction() 0 3 1
A createQueryBuilder() 0 3 1
A isFiltersStateClean() 0 3 1
A merge() 0 3 1
A getHydrator() 0 3 1
A createQuery() 0 3 1
A getFilters() 0 3 1
A persistReal() 0 3 1
A lock() 0 3 1
A getCachedForPersist() 0 3 1
A getClassMetadata() 0 3 1
A flush() 0 2 1
A getConfiguration() 0 3 1
A initializeObject() 0 3 1
A getRepository() 0 3 1
A getCache() 0 3 1
A clear() 0 3 1
A isOpen() 0 3 1
A getMetadataFactory() 0 3 1
A getProxyFactory() 0 3 1
A getReference() 0 3 1
A contains() 0 3 1
A __construct() 0 3 1
A commit() 0 3 1
A close() 0 3 1
A createNamedNativeQuery() 0 3 1
A createNamedQuery() 0 3 1
A getUnitOfWork() 0 3 1
A getConnection() 0 3 1
A persist() 0 4 1
A refresh() 0 3 1
A remove() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like CachedFixtureEntityManager often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use CachedFixtureEntityManager, and based on these observations, apply Extract Interface, too.

1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Test\FixtureLoader\Cache;
12
13
use Doctrine\ORM\EntityManagerInterface;
14
use Doctrine\ORM\Mapping\ClassMetadata;
15
use Doctrine\ORM\Query\ResultSetMapping;
16
17
/**
18
 * This is a proxy entity manager to save in cache all
19
 * fixtures without do a real persist or flush
20
 * @see CachedFixtureExecutor
21
 */
22
class CachedFixtureEntityManager implements EntityManagerInterface
23
{
24
    protected $cachedForPersist = [];
25
26
    /**
27
     * @var EntityManagerInterface
28
     */
29
    protected $em;
30
31
    /**
32
     * @param EntityManagerInterface $em
33
     */
34 21
    public function __construct(EntityManagerInterface $em)
35
    {
36 21
        $this->em = $em;
37 21
    }
38
39
    /**
40
     * @return array
41
     */
42 1
    public function getCachedForPersist(): array
43
    {
44 1
        return $this->cachedForPersist;
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50
    public function find($className, $id)
51
    {
52
        return $this->em->find($className, $id);
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58 1
    public function persist($object)
59
    {
60 1
        $oid = spl_object_hash($object);
61 1
        $this->cachedForPersist[$oid] = $object;
62 1
    }
63
64
    /**
65
     * {@inheritDoc}
66
     */
67 21
    public function persistReal($object)
68
    {
69 21
        $this->em->persist($object);
70 21
    }
71
72
    /**
73
     * {@inheritDoc}
74
     */
75
    public function remove($object)
76
    {
77
        $this->em->remove($object);
78
    }
79
80
    /**
81
     * {@inheritDoc}
82
     */
83
    public function merge($object)
84
    {
85
        return $this->em->merge($object);
86
    }
87
88
    /**
89
     * {@inheritDoc}
90
     */
91 1
    public function clear($objectName = null)
92
    {
93 1
        $this->em->clear($objectName);
94 1
    }
95
96
    /**
97
     * {@inheritDoc}
98
     */
99
    public function detach($object)
100
    {
101
        $this->em->detach($object);
102
    }
103
104
    /**
105
     * {@inheritDoc}
106
     */
107
    public function refresh($object)
108
    {
109
        $this->em->refresh($object);
110
    }
111
112
    /**
113
     * {@inheritDoc}
114
     */
115 1
    public function flush($entity = null)
116
    {
117
118 1
    }
119
120
    /**
121
     * {@inheritDoc}
122
     */
123
    public function flushReal()
124
    {
125
        $this->em->flush();
126
    }
127
128
    /**
129
     * {@inheritDoc}
130
     */
131
    public function getRepository($className)
132
    {
133
        return $this->em->getRepository($className);
134
    }
135
136
    /**
137
     * {@inheritDoc}
138
     */
139 21
    public function getClassMetadata($className): ClassMetadata
140
    {
141 21
        return $this->em->getClassMetadata($className);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->em->getClassMetadata($className) returns the type Doctrine\Common\Persistence\Mapping\ClassMetadata which includes types incompatible with the type-hinted return Doctrine\ORM\Mapping\ClassMetadata.
Loading history...
142
    }
143
144
    /**
145
     * {@inheritDoc}
146
     */
147 21
    public function getMetadataFactory()
148
    {
149 21
        return $this->em->getMetadataFactory();
150
    }
151
152
    /**
153
     * {@inheritDoc}
154
     */
155
    public function initializeObject($obj)
156
    {
157
        $this->em->initializeObject($obj);
158
    }
159
160
    /**
161
     * {@inheritDoc}
162
     */
163
    public function contains($object)
164
    {
165
        return $this->em->contains($object);
166
    }
167
168
    /**
169
     *{@inheritDoc}
170
     */
171
    public function getCache()
172
    {
173
        return $this->em->getCache();
174
    }
175
176
    /**
177
     *{@inheritDoc}
178
     */
179 21
    public function getConnection()
180
    {
181 21
        return $this->em->getConnection();
182
    }
183
184
    /**
185
     *{@inheritDoc}
186
     */
187
    public function getExpressionBuilder()
188
    {
189
        return $this->em->getExpressionBuilder();
190
    }
191
192
    /**
193
     *{@inheritDoc}
194
     */
195
    public function beginTransaction()
196
    {
197
        $this->em->beginTransaction();
198
    }
199
200
    /**
201
     *{@inheritDoc}
202
     */
203 21
    public function transactional($func)
204
    {
205 21
        $this->cachedForPersist = [];
206 21
        $this->em->transactional($func);
207 21
    }
208
209
    /**
210
     *{@inheritDoc}
211
     */
212
    public function commit()
213
    {
214
        $this->em->commit();
215
    }
216
217
    /**
218
     *{@inheritDoc}
219
     */
220
    public function rollback()
221
    {
222
        $this->em->rollback();
223
    }
224
225
    /**
226
     *{@inheritDoc}
227
     */
228
    public function createQuery($dql = '')
229
    {
230
        return $this->em->createQuery($dql);
231
    }
232
233
    /**
234
     *{@inheritDoc}
235
     */
236
    public function createNamedQuery($name)
237
    {
238
        return $this->em->createNamedQuery($name);
239
    }
240
241
    /**
242
     *{@inheritDoc}
243
     */
244
    public function createNativeQuery($sql, ResultSetMapping $rsm)
245
    {
246
        return $this->em->createNativeQuery($sql, $rsm);
247
    }
248
249
    /**
250
     *{@inheritDoc}
251
     */
252
    public function createNamedNativeQuery($name)
253
    {
254
        return $this->em->createNamedNativeQuery($name);
255
    }
256
257
    /**
258
     *{@inheritDoc}
259
     */
260
    public function createQueryBuilder()
261
    {
262
        return $this->em->createQueryBuilder();
263
    }
264
265
    /**
266
     *{@inheritDoc}
267
     */
268
    public function getReference($entityName, $id)
269
    {
270
        return $this->em->getReference($entityName, $id);
271
    }
272
273
    /**
274
     *{@inheritDoc}
275
     */
276
    public function getPartialReference($entityName, $identifier)
277
    {
278
        return $this->em->getPartialReference($entityName, $identifier);
279
    }
280
281
    /**
282
     *{@inheritDoc}
283
     */
284
    public function close()
285
    {
286
        $this->em->close();
287
    }
288
289
    /**
290
     *{@inheritDoc}
291
     */
292
    public function copy($entity, $deep = false)
293
    {
294
        return $this->em->copy($entity, $deep);
295
    }
296
297
    /**
298
     *{@inheritDoc}
299
     */
300
    public function lock($entity, $lockMode, $lockVersion = null)
301
    {
302
        $this->em->lock($entity, $lockMode, $lockVersion);
303
    }
304
305
    /**
306
     *{@inheritDoc}
307
     */
308 21
    public function getEventManager()
309
    {
310 21
        return $this->em->getEventManager();
311
    }
312
313
    /**
314
     *{@inheritDoc}
315
     */
316 21
    public function getConfiguration()
317
    {
318 21
        return $this->em->getConfiguration();
319
    }
320
321
    /**
322
     *{@inheritDoc}
323
     */
324
    public function isOpen()
325
    {
326
        return $this->em->isOpen();
327
    }
328
329
    /**
330
     *{@inheritDoc}
331
     */
332
    public function getUnitOfWork()
333
    {
334
        return $this->em->getUnitOfWork();
335
    }
336
337
    /**
338
     *{@inheritDoc}
339
     */
340
    public function getHydrator($hydrationMode)
341
    {
342
        return $this->em->getHydrator($hydrationMode);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManagerInterface::getHydrator() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

342
        return /** @scrutinizer ignore-deprecated */ $this->em->getHydrator($hydrationMode);
Loading history...
343
    }
344
345
    /**
346
     *{@inheritDoc}
347
     */
348
    public function newHydrator($hydrationMode)
349
    {
350
        return $this->em->newHydrator($hydrationMode);
351
    }
352
353
    /**
354
     *{@inheritDoc}
355
     */
356
    public function getProxyFactory()
357
    {
358
        return $this->em->getProxyFactory();
359
    }
360
361
    /**
362
     *{@inheritDoc}
363
     */
364
    public function getFilters()
365
    {
366
        return $this->em->getFilters();
367
    }
368
369
    /**
370
     *{@inheritDoc}
371
     */
372
    public function isFiltersStateClean()
373
    {
374
        return $this->em->isFiltersStateClean();
375
    }
376
377
    /**
378
     *{@inheritDoc}
379
     */
380
    public function hasFilters()
381
    {
382
        return $this->em->hasFilters();
383
    }
384
}
385