Conditions | 2 |
Paths | 1 |
Total Lines | 108 |
Code Lines | 72 |
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 |
||
32 | public function buildForm(FormInterface $form) |
||
33 | { |
||
34 | $currentCategory = $this->getCurrentCategory(); |
||
35 | |||
36 | $requiredData = $form->addChild($this->getElement('nested_fieldset', [ |
||
37 | 'name' => 'required_data', |
||
38 | 'label' => 'common.fieldset.general', |
||
39 | ])); |
||
40 | |||
41 | $languageData = $requiredData->addChild($this->getElement('language_fieldset', [ |
||
42 | 'name' => 'translations', |
||
43 | 'label' => 'common.fieldset.translations', |
||
44 | 'transformer' => $this->getRepositoryTransformer('translation', $this->get('category.repository')), |
||
45 | ])); |
||
46 | |||
47 | $name = $languageData->addChild($this->getElement('text_field', [ |
||
48 | 'name' => 'name', |
||
49 | 'label' => 'common.label.name', |
||
50 | 'rules' => [ |
||
51 | $this->getRule('required'), |
||
52 | ], |
||
53 | ])); |
||
54 | |||
55 | $languageData->addChild($this->getElement('slug_field', [ |
||
56 | 'name' => 'slug', |
||
57 | 'label' => 'category.label.slug', |
||
58 | 'name_field' => $name, |
||
59 | 'generate_route' => 'route.generate', |
||
60 | 'translatable_id' => $this->getRequestHelper()->getAttributesBagParam('id'), |
||
61 | 'rules' => [ |
||
62 | $this->getRule('required'), |
||
63 | ], |
||
64 | ])); |
||
65 | |||
66 | $requiredData->addChild($this->getElement('checkbox', [ |
||
67 | 'name' => 'enabled', |
||
68 | 'label' => 'category.label.enabled', |
||
69 | 'comment' => 'category.comment.enabled', |
||
70 | ])); |
||
71 | |||
72 | $requiredData->addChild($this->getElement('text_field', [ |
||
73 | 'name' => 'hierarchy', |
||
74 | 'label' => 'common.label.hierarchy', |
||
75 | 'rules' => [ |
||
76 | $this->getRule('required'), |
||
77 | ], |
||
78 | ])); |
||
79 | |||
80 | $requiredData->addChild($this->getElement('text_field', [ |
||
81 | 'name' => 'symbol', |
||
82 | 'label' => 'common.label.symbol', |
||
83 | ])); |
||
84 | |||
85 | $requiredData->addChild($this->getElement('tree', [ |
||
86 | 'name' => 'parent', |
||
87 | 'label' => 'category.label.parent', |
||
88 | 'choosable' => true, |
||
89 | 'selectable' => false, |
||
90 | 'sortable' => false, |
||
91 | 'clickable' => false, |
||
92 | 'items' => $this->getCategoryParentOptions($currentCategory), |
||
93 | 'restrict' => $currentCategory instanceof Category ? $currentCategory->getId() : 0, |
||
94 | 'transformer' => $this->getRepositoryTransformer('entity', $this->get('category.repository')), |
||
95 | ])); |
||
96 | |||
97 | $descriptionData = $form->addChild($this->getElement('nested_fieldset', [ |
||
98 | 'name' => 'description_data', |
||
99 | 'label' => 'category.form.fieldset.description', |
||
100 | ])); |
||
101 | |||
102 | $languageData = $descriptionData->addChild($this->getElement('language_fieldset', [ |
||
103 | 'name' => 'translations', |
||
104 | 'label' => 'common.fieldset.translations', |
||
105 | 'transformer' => $this->getRepositoryTransformer('translation', $this->get('category.repository')), |
||
106 | ])); |
||
107 | |||
108 | $languageData->addChild($this->getElement('rich_text_editor', [ |
||
109 | 'name' => 'shortDescription', |
||
110 | 'label' => 'common.label.short_description', |
||
111 | ])); |
||
112 | |||
113 | $languageData->addChild($this->getElement('rich_text_editor', [ |
||
114 | 'name' => 'description', |
||
115 | 'label' => 'common.label.description', |
||
116 | ])); |
||
117 | |||
118 | $mediaData = $form->addChild($this->getElement('nested_fieldset', [ |
||
119 | 'name' => 'media_data', |
||
120 | 'label' => 'common.fieldset.photos', |
||
121 | ])); |
||
122 | |||
123 | $mediaData->addChild($this->getElement('image', [ |
||
124 | 'name' => 'photo', |
||
125 | 'label' => 'form.media_data.image_id', |
||
126 | 'repeat_min' => 0, |
||
127 | 'repeat_max' => 1, |
||
128 | 'transformer' => $this->getRepositoryTransformer('media_entity', $this->get('media.repository')), |
||
129 | 'session_id' => $this->getRequestHelper()->getSessionId(), |
||
130 | 'session_name' => $this->getRequestHelper()->getSessionName(), |
||
131 | ])); |
||
132 | |||
133 | $this->addMetadataFieldset($form, $this->get('category.repository')); |
||
134 | |||
135 | $this->addShopsFieldset($form); |
||
136 | |||
137 | $form->addFilter($this->getFilter('trim')); |
||
138 | $form->addFilter($this->getFilter('secure')); |
||
139 | } |
||
140 | |||
171 |