| Conditions | 2 |
| Paths | 2 |
| Total Lines | 63 |
| Code Lines | 44 |
| 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 |
||
| 20 | protected function getEntityManager() |
||
| 21 | { |
||
| 22 | if (!$this->entityManager) { |
||
| 23 | $regionsConfig = new RegionsConfiguration(); |
||
| 24 | |||
| 25 | $cacheDriver = new GH7708ArrayCacheMock(); |
||
| 26 | |||
| 27 | $cacheFactory = new DefaultCacheFactory($regionsConfig, $cacheDriver); |
||
| 28 | |||
| 29 | $conn = TestUtil::getConnection(); |
||
| 30 | |||
| 31 | $config = Setup::createAnnotationMetadataConfiguration([]); |
||
| 32 | |||
| 33 | $config->setMetadataCacheImpl($cacheDriver); |
||
| 34 | $config->setQueryCacheImpl($cacheDriver); |
||
| 35 | $config->setResultCacheImpl($cacheDriver); |
||
| 36 | $config->setHydrationCacheImpl($cacheDriver); |
||
| 37 | |||
| 38 | $config->setSecondLevelCacheEnabled(); |
||
| 39 | $secondLevelCacheConfig = $config->getSecondLevelCacheConfiguration(); |
||
| 40 | $secondLevelCacheConfig->setCacheFactory($cacheFactory); |
||
| 41 | |||
| 42 | $this->entityManager = EntityManager::create($conn, $config); |
||
| 43 | |||
| 44 | // Creating a schema |
||
| 45 | |||
| 46 | $schemaTool = new SchemaTool($this->entityManager); |
||
| 47 | $schemaTool->createSchema([ |
||
| 48 | $this->entityManager->getClassMetadata(GH7708Car::class), |
||
| 49 | $this->entityManager->getClassMetadata(GH7708Model::class), |
||
| 50 | $this->entityManager->getClassMetadata(GH7708Drive::class) |
||
| 51 | ]); |
||
| 52 | |||
| 53 | // Populating with data |
||
| 54 | |||
| 55 | $frontDrive = new GH7708Drive('Front'); |
||
| 56 | $rearDrive = new GH7708Drive('Rear'); |
||
| 57 | $fullDrive = new GH7708Drive('Full'); |
||
| 58 | |||
| 59 | $this->entityManager->persist(new GH7708Car(new GH7708Model('Audi A4'), $rearDrive)); |
||
| 60 | $this->entityManager->persist(new GH7708Car(new GH7708Model('Audi A5'), $rearDrive)); |
||
| 61 | $this->entityManager->persist(new GH7708Car(new GH7708Model('Audi A6'), $rearDrive)); |
||
| 62 | $this->entityManager->persist(new GH7708Car(new GH7708Model('Audi A8'), $rearDrive)); |
||
| 63 | $this->entityManager->persist(new GH7708Car(new GH7708Model('Audi Q3'), $fullDrive)); |
||
| 64 | $this->entityManager->persist(new GH7708Car(new GH7708Model('Audi Q5'), $fullDrive)); |
||
| 65 | $this->entityManager->persist(new GH7708Car(new GH7708Model('Audi Q7'), $fullDrive)); |
||
| 66 | $this->entityManager->persist(new GH7708Car(new GH7708Model('BMW 1-series'), $rearDrive)); |
||
| 67 | $this->entityManager->persist(new GH7708Car(new GH7708Model('BMW 3-series'), $rearDrive)); |
||
| 68 | $this->entityManager->persist(new GH7708Car(new GH7708Model('BMW 5-series'), $rearDrive)); |
||
| 69 | $this->entityManager->persist(new GH7708Car(new GH7708Model('BMW 7-series'), $rearDrive)); |
||
| 70 | $this->entityManager->persist(new GH7708Car(new GH7708Model('BMW X1'), $fullDrive)); |
||
| 71 | $this->entityManager->persist(new GH7708Car(new GH7708Model('BMW X3'), $fullDrive)); |
||
| 72 | $this->entityManager->persist(new GH7708Car(new GH7708Model('BMW X5'), $fullDrive)); |
||
| 73 | $this->entityManager->persist(new GH7708Car(new GH7708Model('BMW X6'), $fullDrive)); |
||
| 74 | $this->entityManager->persist(new GH7708Car(new GH7708Model('Volkswagen Golf'), $frontDrive)); |
||
| 75 | $this->entityManager->persist(new GH7708Car(new GH7708Model('Volkswagen Jetta'), $frontDrive)); |
||
| 76 | $this->entityManager->persist(new GH7708Car(new GH7708Model('Volkswagen Passat'), $frontDrive)); |
||
| 77 | $this->entityManager->persist(new GH7708Car(new GH7708Model('Volkswagen Polo'), $frontDrive)); |
||
| 78 | $this->entityManager->persist(new GH7708Car(new GH7708Model('Volkswagen Tiguan'), $fullDrive)); |
||
| 79 | |||
| 80 | $this->entityManager->flush(); |
||
| 81 | } |
||
| 82 | return $this->entityManager; |
||
| 83 | } |
||
| 210 |