Conditions | 3 |
Paths | 1 |
Total Lines | 93 |
Code Lines | 64 |
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 |
||
118 | protected function initForm(FormFactoryInterface $factory, $data = null) |
||
119 | { |
||
120 | $builder = $factory->createNamedBuilder( |
||
121 | 'news', |
||
122 | TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\FormType', 'form'), |
||
123 | $data, |
||
124 | array( |
||
125 | 'data_class' => $this->getClassName() |
||
126 | ) |
||
127 | ); |
||
128 | |||
129 | $builder->add( |
||
130 | 'title', |
||
131 | TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\TextType', 'text'), |
||
132 | array( |
||
133 | 'label' => 'admin.news.list.title', |
||
134 | ) |
||
135 | ); |
||
136 | |||
137 | $builder->add( |
||
138 | 'date', |
||
139 | TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\DateType', 'date'), |
||
140 | array( |
||
141 | 'label' => 'admin.news.list.date', |
||
142 | 'widget' => 'single_text', |
||
143 | 'required' => false, |
||
144 | ) |
||
145 | ); |
||
146 | |||
147 | $builder->add( |
||
148 | 'created_at', |
||
149 | TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\DateType', 'date'), |
||
150 | array( |
||
151 | 'label' => 'admin.news.list.created_at', |
||
152 | 'widget' => 'single_text' |
||
153 | ) |
||
154 | ); |
||
155 | |||
156 | $builder->add( |
||
157 | 'visible', |
||
158 | TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\CheckboxType', 'checkbox'), |
||
159 | array( |
||
160 | 'label' => 'admin.news.list.visible', |
||
161 | 'required' => false, |
||
162 | ) |
||
163 | ); |
||
164 | |||
165 | $builder->add( |
||
166 | 'creator_email', |
||
167 | TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\EmailType', 'email'), |
||
168 | array( |
||
169 | 'label' => 'admin.news.list.creator_email' |
||
170 | ) |
||
171 | ); |
||
172 | |||
173 | $builder->add( |
||
174 | 'photo', |
||
175 | TypeSolver::getFormType('FSi\Bundle\DoctrineExtensionsBundle\Form\Type\FSi\ImageType', 'fsi_image'), |
||
176 | array( |
||
177 | 'label' => 'admin.news.list.photo' |
||
178 | ) |
||
179 | ); |
||
180 | |||
181 | $builder->add( |
||
182 | 'tags', |
||
183 | TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\CollectionType', 'collection'), |
||
184 | array( |
||
185 | TypeSolver::hasCollectionEntryTypeOption() ? 'entry_type' : 'type' => |
||
186 | TypeSolver::getFormType('FSi\FixturesBundle\Form\TagType', new TagType()), |
||
187 | 'label' => 'admin.news.list.tags', |
||
188 | 'allow_add' => true, |
||
189 | 'allow_delete' => true, |
||
190 | 'by_reference' => false, |
||
191 | ) |
||
192 | ); |
||
193 | |||
194 | $builder->add( |
||
195 | 'nonEditableTags', |
||
196 | TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\CollectionType', 'collection'), |
||
197 | array( |
||
198 | TypeSolver::hasCollectionEntryTypeOption() ? 'entry_type' : 'type' => |
||
199 | TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\TextType', 'text'), |
||
200 | 'data' => new ArrayCollection(['Tag 1', 'Tag 2', 'Tag 3']), |
||
201 | 'label' => 'admin.news.list.non_editable_tags', |
||
202 | 'allow_add' => false, |
||
203 | 'allow_delete' => false, |
||
204 | 'mapped' => false, |
||
205 | 'required' => false |
||
206 | ) |
||
207 | ); |
||
208 | |||
209 | return $builder->getForm(); |
||
210 | } |
||
211 | } |
||
212 |