Conditions | 11 |
Paths | 20 |
Total Lines | 115 |
Code Lines | 79 |
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 |
||
70 | protected function configureFormFields(FormMapper $form): void |
||
71 | { |
||
72 | $gameOptions = []; |
||
73 | if (($this->hasRequest()) && ($this->isCurrentRoute('create'))) { |
||
74 | $idGame = $this->getRequest()->get('idGame', null); |
||
75 | if ($idGame !== null) { |
||
76 | $this->getRequest()->getSession()->set('vgrcorebundle_admin_group.idGame', $idGame); |
||
77 | } |
||
78 | |||
79 | if ($this->getRequest()->getSession()->has('vgrcorebundle_admin_group.idGame')) { |
||
80 | $idGame = $this->getRequest()->getSession()->get('vgrcorebundle_admin_group.idGame'); |
||
81 | $entityManager = $this->getModelManager() |
||
82 | ->getEntityManager('VideoGamesRecords\CoreBundle\Entity\Game'); |
||
|
|||
83 | $game = $entityManager->getReference('VideoGamesRecords\CoreBundle\Entity\Game', $idGame); |
||
84 | $gameOptions = ['data' => $game]; |
||
85 | } |
||
86 | } |
||
87 | |||
88 | $form |
||
89 | ->add('id', TextType::class, [ |
||
90 | 'label' => 'label.id', |
||
91 | 'attr' => [ |
||
92 | 'readonly' => true, |
||
93 | ] |
||
94 | ]) |
||
95 | ->add('libGroupEn', TextType::class, [ |
||
96 | 'label' => 'label.name.en', |
||
97 | 'required' => true, |
||
98 | ]) |
||
99 | ->add('libGroupFr', TextType::class, [ |
||
100 | 'label' => 'label.name.fr', |
||
101 | 'required' => false, |
||
102 | ]) |
||
103 | ->add('isRank', CheckboxType::class, [ |
||
104 | 'label' => 'label.boolRanking', |
||
105 | 'required' => false, |
||
106 | ]) |
||
107 | ->add( |
||
108 | 'orderBy', |
||
109 | ChoiceType::class, |
||
110 | [ |
||
111 | 'label' => 'label.orderBy', |
||
112 | 'choices' => GroupOrderBy::getStatusChoices(), |
||
113 | ] |
||
114 | ) |
||
115 | ; |
||
116 | |||
117 | if ($this->isCurrentRoute('create') || $this->isCurrentRoute('edit')) { |
||
118 | $btnCalalogue = $this->isCurrentRoute('create'); |
||
119 | $form-> |
||
120 | add( |
||
121 | 'game', |
||
122 | ModelListType::class, |
||
123 | array_merge( |
||
124 | $gameOptions, |
||
125 | [ |
||
126 | 'data_class' => null, |
||
127 | 'btn_add' => false, |
||
128 | 'btn_list' => $btnCalalogue, |
||
129 | 'btn_edit' => false, |
||
130 | 'btn_delete' => false, |
||
131 | 'btn_catalogue' => $btnCalalogue, |
||
132 | 'label' => 'label.game', |
||
133 | ] |
||
134 | ) |
||
135 | ); |
||
136 | } |
||
137 | |||
138 | $form->add('isDlc', CheckboxType::class, [ |
||
139 | 'label' => 'label.isDlc', |
||
140 | 'required' => false, |
||
141 | ]); |
||
142 | |||
143 | $subject = $this->getSubject(); |
||
144 | |||
145 | if ( |
||
146 | (strpos( |
||
147 | $this->getRequest() |
||
148 | ->getPathInfo(), |
||
149 | 'videogamesrecords/core/group' |
||
150 | ) || (($this->getRequest() |
||
151 | ->getPathInfo() == '/admin/core/append-form-field-element') && ($this->getRequest( |
||
152 | )->query->get('_sonata_admin') == 'sonata.admin.vgr.group'))) && (count( |
||
153 | $subject->getCharts() |
||
154 | ) < 50) |
||
155 | ) { |
||
156 | $form->end() |
||
157 | ->with('label.charts') |
||
158 | ->add( |
||
159 | 'charts', |
||
160 | CollectionType::class, |
||
161 | array( |
||
162 | 'label' => 'label.charts', |
||
163 | 'by_reference' => false, |
||
164 | 'help' => 'label.libs.help', |
||
165 | 'type_options' => array( |
||
166 | // Prevents the "Delete" option from being displayed |
||
167 | 'delete' => true, |
||
168 | 'delete_options' => array( |
||
169 | // You may otherwise choose to put the field but hide it |
||
170 | 'type' => CheckboxType::class, |
||
171 | // In that case, you need to fill in the options as well |
||
172 | 'type_options' => array( |
||
173 | 'mapped' => false, |
||
174 | 'required' => false, |
||
175 | ) |
||
176 | ) |
||
177 | ), |
||
178 | ), |
||
179 | array( |
||
180 | 'edit' => 'inline', |
||
181 | 'inline' => 'table', |
||
182 | ) |
||
183 | ) |
||
184 | ->end(); |
||
185 | } |
||
279 |