| Conditions | 8 |
| Paths | 1 |
| Total Lines | 66 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 21 | protected function configureFormFields(FormMapper $formMapper) |
||
| 22 | { |
||
| 23 | $performanceEventId = $this->getRequest()->query->get('performanceEvent_id'); |
||
| 24 | $formMapper |
||
| 25 | ->add('venueSector', null, [ |
||
| 26 | 'required' => true, |
||
| 27 | 'query_builder' => function (EntityRepository $rep) use ($performanceEventId) { |
||
| 28 | $qb = $rep->createQueryBuilder('p'); |
||
| 29 | if ($performanceEventId) { |
||
| 30 | $performanceEvent = $this->getConfigurationPool() |
||
| 31 | ->getContainer()->get('doctrine.orm.default_entity_manager') |
||
| 32 | ->getRepository('AppBundle\Entity\PerformanceEvent') |
||
| 33 | ->find($performanceEventId); |
||
| 34 | $venueSectors = $performanceEvent->getVenue()->getVenueSector(); |
||
| 35 | foreach ($venueSectors as $sector) { |
||
| 36 | $qb->orWhere("p.id = ".$sector->getId()); |
||
| 37 | } |
||
| 38 | } |
||
| 39 | if (($this->getSubject() !== null) && ($performanceEventId === null)) { |
||
| 40 | if ($this->getSubject()->getPerformanceEvent() !== null) { |
||
| 41 | $performanceEvent = $this->getSubject()->getPerformanceEvent(); |
||
| 42 | $venueSectors = $performanceEvent->getVenue()->getVenueSector(); |
||
| 43 | foreach ($venueSectors as $sector) { |
||
| 44 | $qb->orWhere("p.id = ".$sector->getId()); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | } |
||
| 48 | return $qb; |
||
| 49 | } |
||
| 50 | ]) |
||
| 51 | ->add('color', 'sonata_type_color_selector', [ |
||
| 52 | 'label' => 'Color' |
||
| 53 | ]) |
||
| 54 | ->add('rows', TextType::class, [ |
||
| 55 | 'required' => true, |
||
| 56 | 'attr' => [ |
||
| 57 | 'placeholder' => '1-5,6,7,10-15', |
||
| 58 | ] |
||
| 59 | ]) |
||
| 60 | ->add('places', TextType::class, [ |
||
| 61 | 'required' => false, |
||
| 62 | 'attr' => [ |
||
| 63 | 'placeholder' => '1-5,6,7,10-15', |
||
| 64 | ] |
||
| 65 | ]) |
||
| 66 | ->add('price', IntegerType::class, [ |
||
| 67 | 'required' => true, |
||
| 68 | 'attr' => [ |
||
| 69 | 'placeholder' => '50', |
||
| 70 | ] |
||
| 71 | ]) |
||
| 72 | ->add('performanceEvent', null, [ |
||
| 73 | 'required' => true, |
||
| 74 | 'attr' => ['class' => 'hidden'], |
||
| 75 | 'label' => false, |
||
| 76 | 'query_builder' => function (EntityRepository $rep) use ($performanceEventId) { |
||
| 77 | $qb = $rep->createQueryBuilder('p'); |
||
| 78 | if ($performanceEventId) { |
||
| 79 | $qb ->where('p.id = :performanceEvent_id') |
||
| 80 | ->setParameter('performanceEvent_id', $performanceEventId); |
||
| 81 | } |
||
| 82 | return $qb; |
||
| 83 | } |
||
| 84 | ]) |
||
| 85 | ; |
||
| 86 | } |
||
| 87 | } |
||
| 88 |