| Conditions | 11 |
| Paths | 20 |
| Total Lines | 130 |
| Code Lines | 91 |
| 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 |
||
| 69 | protected function configureFormFields(FormMapper $form): void |
||
| 70 | { |
||
| 71 | $gameOptions = []; |
||
| 72 | if (($this->hasRequest()) && ($this->isCurrentRoute('create'))) { |
||
| 73 | $idGame = $this->getRequest()->get('idGame', null); |
||
| 74 | if ($idGame !== null) { |
||
| 75 | $this->getRequest()->getSession()->set('vgrcorebundle_admin_group.idGame', $idGame); |
||
| 76 | } |
||
| 77 | |||
| 78 | if ($this->getRequest()->getSession()->has('vgrcorebundle_admin_group.idGame')) { |
||
| 79 | $idGame = $this->getRequest()->getSession()->get('vgrcorebundle_admin_group.idGame'); |
||
| 80 | $entityManager = $this->getModelManager() |
||
| 81 | ->getEntityManager('VideoGamesRecords\CoreBundle\Entity\Game'); |
||
|
|
|||
| 82 | $game = $entityManager->getReference('VideoGamesRecords\CoreBundle\Entity\Game', $idGame); |
||
| 83 | $gameOptions = ['data' => $game]; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | $form |
||
| 88 | // Informations principales - Colonne 1 |
||
| 89 | ->with('section.general.information', [ |
||
| 90 | 'class' => 'col-md-6', |
||
| 91 | 'label' => 'section.general.information', |
||
| 92 | 'box_class' => 'box box-primary' |
||
| 93 | ]) |
||
| 94 | ->add('id', TextType::class, [ |
||
| 95 | 'label' => 'group.form.id', |
||
| 96 | 'attr' => [ |
||
| 97 | 'readonly' => true, |
||
| 98 | ] |
||
| 99 | ]) |
||
| 100 | ->add('libGroupEn', TextType::class, [ |
||
| 101 | 'label' => 'group.form.name.en', |
||
| 102 | 'required' => true, |
||
| 103 | ]) |
||
| 104 | ->add('libGroupFr', TextType::class, [ |
||
| 105 | 'label' => 'group.form.name.fr', |
||
| 106 | 'required' => false, |
||
| 107 | ]); |
||
| 108 | |||
| 109 | // Ajout du jeu selon le contexte |
||
| 110 | if ($this->isCurrentRoute('create') || $this->isCurrentRoute('edit')) { |
||
| 111 | $btnCatalogue = $this->isCurrentRoute('create'); |
||
| 112 | $form->add( |
||
| 113 | 'game', |
||
| 114 | ModelListType::class, |
||
| 115 | array_merge( |
||
| 116 | $gameOptions, |
||
| 117 | [ |
||
| 118 | 'data_class' => null, |
||
| 119 | 'btn_add' => false, |
||
| 120 | 'btn_list' => $btnCatalogue, |
||
| 121 | 'btn_edit' => false, |
||
| 122 | 'btn_delete' => false, |
||
| 123 | 'btn_catalogue' => $btnCatalogue, |
||
| 124 | 'label' => 'group.form.game', |
||
| 125 | ] |
||
| 126 | ) |
||
| 127 | ); |
||
| 128 | } |
||
| 129 | |||
| 130 | $form->end() |
||
| 131 | |||
| 132 | // Configuration - Colonne 2 |
||
| 133 | ->with('section.configuration', [ |
||
| 134 | 'class' => 'col-md-6', |
||
| 135 | 'label' => 'section.configuration', |
||
| 136 | 'box_class' => 'box box-success' |
||
| 137 | ]) |
||
| 138 | ->add('isRank', CheckboxType::class, [ |
||
| 139 | 'label' => 'group.form.boolRanking', |
||
| 140 | 'required' => false, |
||
| 141 | ]) |
||
| 142 | ->add( |
||
| 143 | 'orderBy', |
||
| 144 | ChoiceType::class, |
||
| 145 | [ |
||
| 146 | 'label' => 'group.form.orderBy', |
||
| 147 | 'choices' => GroupOrderBy::getStatusChoices(), |
||
| 148 | ] |
||
| 149 | ) |
||
| 150 | ->add('isDlc', CheckboxType::class, [ |
||
| 151 | 'label' => 'group.form.isDlc', |
||
| 152 | 'required' => false, |
||
| 153 | ]) |
||
| 154 | ->end(); |
||
| 155 | |||
| 156 | // Charts - Section complète si présents |
||
| 157 | $subject = $this->getSubject(); |
||
| 158 | if ( |
||
| 159 | (strpos( |
||
| 160 | $this->getRequest() |
||
| 161 | ->getPathInfo(), |
||
| 162 | 'videogamesrecords/core/group' |
||
| 163 | ) || (($this->getRequest() |
||
| 164 | ->getPathInfo() == '/admin/core/append-form-field-element') && ($this->getRequest( |
||
| 165 | )->query->get('_sonata_admin') == 'sonata.admin.vgr.group'))) && (count( |
||
| 166 | $subject->getCharts() |
||
| 167 | ) < 50) |
||
| 168 | ) { |
||
| 169 | $form |
||
| 170 | ->with('group.form.charts', [ |
||
| 171 | 'class' => 'col-md-12', |
||
| 172 | 'label' => 'group.form.charts', |
||
| 173 | 'box_class' => 'box box-info' |
||
| 174 | ]) |
||
| 175 | ->add( |
||
| 176 | 'charts', |
||
| 177 | CollectionType::class, |
||
| 178 | array( |
||
| 179 | 'label' => 'group.form.charts', |
||
| 180 | 'by_reference' => false, |
||
| 181 | 'help' => 'group.form.libs', |
||
| 182 | 'type_options' => array( |
||
| 183 | 'delete' => true, |
||
| 184 | 'delete_options' => array( |
||
| 185 | 'type' => CheckboxType::class, |
||
| 186 | 'type_options' => array( |
||
| 187 | 'mapped' => false, |
||
| 188 | 'required' => false, |
||
| 189 | ) |
||
| 190 | ) |
||
| 191 | ), |
||
| 192 | ), |
||
| 193 | array( |
||
| 194 | 'edit' => 'inline', |
||
| 195 | 'inline' => 'table', |
||
| 196 | ) |
||
| 197 | ) |
||
| 198 | ->end(); |
||
| 199 | } |
||
| 318 |