Conditions | 1 |
Paths | 1 |
Total Lines | 112 |
Code Lines | 71 |
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 |
||
30 | public function buildForm(FormInterface $form) |
||
31 | { |
||
32 | $currencies = $this->get('currency.dataset.admin')->getResult('select', ['order_by' => 'code'], [ |
||
33 | 'label_column' => 'code', |
||
34 | 'value_column' => 'code' |
||
35 | ]); |
||
36 | |||
37 | $requiredData = $form->addChild($this->getElement('nested_fieldset', [ |
||
38 | 'name' => 'required_data', |
||
39 | 'label' => 'common.fieldset.general' |
||
40 | ])); |
||
41 | |||
42 | $languageData = $requiredData->addChild($this->getElement('language_fieldset', [ |
||
43 | 'name' => 'translations', |
||
44 | 'label' => 'common.fieldset.translations', |
||
45 | 'transformer' => $this->getRepositoryTransformer('translation', $this->get('coupon.repository')) |
||
46 | ])); |
||
47 | |||
48 | $languageData->addChild($this->getElement('text_field', [ |
||
49 | 'name' => 'name', |
||
50 | 'label' => 'common.label.name', |
||
51 | 'rules' => [ |
||
52 | $this->getRule('required') |
||
53 | ], |
||
54 | ])); |
||
55 | |||
56 | $languageData->addChild($this->getElement('text_area', [ |
||
57 | 'name' => 'description', |
||
58 | 'label' => 'common.label.description', |
||
59 | ])); |
||
60 | |||
61 | $requiredData->addChild($this->getElement('date', [ |
||
62 | 'name' => 'validFrom', |
||
63 | 'label' => 'common.label.valid_from', |
||
64 | 'transformer' => new DateTransformer('m/d/Y'), |
||
65 | ])); |
||
66 | |||
67 | $requiredData->addChild($this->getElement('date', [ |
||
68 | 'name' => 'validTo', |
||
69 | 'label' => 'common.label.valid_to', |
||
70 | 'transformer' => new DateTransformer('m/d/Y'), |
||
71 | ])); |
||
72 | |||
73 | $requiredData->addChild($this->getElement('text_field', [ |
||
74 | 'name' => 'code', |
||
75 | 'label' => 'common.label.code', |
||
76 | 'rules' => [ |
||
77 | $this->getRule('required') |
||
78 | ], |
||
79 | ])); |
||
80 | |||
81 | $requiredData->addChild($this->getElement('text_field', [ |
||
82 | 'name' => 'clientUsageLimit', |
||
83 | 'label' => 'coupon.label.client_usage_limit', |
||
84 | 'rules' => [ |
||
85 | $this->getRule('required') |
||
86 | ], |
||
87 | ])); |
||
88 | |||
89 | $requiredData->addChild($this->getElement('text_field', [ |
||
90 | 'name' => 'globalUsageLimit', |
||
91 | 'label' => 'coupon.label.global_usage_limit', |
||
92 | 'rules' => [ |
||
93 | $this->getRule('required') |
||
94 | ], |
||
95 | ])); |
||
96 | |||
97 | $discountPane = $form->addChild($this->getElement('nested_fieldset', [ |
||
98 | 'name' => 'discount_pane', |
||
99 | 'label' => 'coupon.fieldset.discount_settings' |
||
100 | ])); |
||
101 | |||
102 | $discountPane->addChild($this->getElement('select', [ |
||
103 | 'name' => 'currency', |
||
104 | 'label' => 'common.label.currency', |
||
105 | 'options' => $currencies, |
||
106 | ])); |
||
107 | |||
108 | $discountPane->addChild($this->getElement('select', [ |
||
109 | 'name' => 'modifierType', |
||
110 | 'label' => 'coupon.label.modifier_type', |
||
111 | 'options' => $this->getModifierTypes() |
||
112 | ])); |
||
113 | |||
114 | $discountPane->addChild($this->getElement('text_field', [ |
||
115 | 'name' => 'modifierValue', |
||
116 | 'label' => 'coupon.label.modifier_value', |
||
117 | 'rules' => [ |
||
118 | $this->getRule('required') |
||
119 | ], |
||
120 | ])); |
||
121 | |||
122 | $discountPane->addChild($this->getElement('text_field', [ |
||
123 | 'name' => 'minimumOrderValue', |
||
124 | 'label' => 'coupon.label.minimum_order_value', |
||
125 | 'rules' => [ |
||
126 | $this->getRule('required') |
||
127 | ], |
||
128 | ])); |
||
129 | |||
130 | $discountPane->addChild($this->getElement('checkbox', [ |
||
131 | 'name' => 'excludePromotions', |
||
132 | 'label' => 'coupon.label.exclude_promotions', |
||
133 | 'rules' => [ |
||
134 | $this->getRule('required') |
||
135 | ], |
||
136 | ])); |
||
137 | |||
138 | $form->addFilter($this->getFilter('no_code')); |
||
139 | $form->addFilter($this->getFilter('trim')); |
||
140 | $form->addFilter($this->getFilter('secure')); |
||
141 | } |
||
142 | |||
151 |