Conditions | 3 |
Paths | 4 |
Total Lines | 129 |
Code Lines | 84 |
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 | $orderStatuses = $this->get('order_status.dataset.admin')->getResult('select'); |
||
35 | $options = []; |
||
36 | $processors = $this->getPaymentProcessorCollection(); |
||
37 | $processorKeys = $processors->keys(); |
||
38 | foreach ($processors->all() as $processor) { |
||
39 | $processorName = $processor->getConfigurator()->getName(); |
||
40 | $options[$processorName] = $processorName; |
||
41 | } |
||
42 | |||
43 | $defaultProcessor = reset($processorKeys); |
||
44 | |||
45 | $requiredData = $form->addChild($this->getElement('nested_fieldset', [ |
||
46 | 'name' => 'required_data', |
||
47 | 'label' => 'common.fieldset.general', |
||
48 | ])); |
||
49 | |||
50 | $languageData = $requiredData->addChild($this->getElement('language_fieldset', [ |
||
51 | 'name' => 'translations', |
||
52 | 'label' => 'common.fieldset.translations', |
||
53 | 'transformer' => $this->getRepositoryTransformer('translation', $this->get('payment_method.repository')), |
||
54 | ])); |
||
55 | |||
56 | $languageData->addChild($this->getElement('text_field', [ |
||
57 | 'name' => 'name', |
||
58 | 'label' => 'common.label.name', |
||
59 | 'rules' => [ |
||
60 | $this->getRule('required'), |
||
61 | ], |
||
62 | ])); |
||
63 | |||
64 | $processorType = $requiredData->addChild($this->getElement('select', [ |
||
65 | 'name' => 'processor', |
||
66 | 'label' => 'payment_method.label.processor', |
||
67 | 'options' => $options, |
||
68 | 'default' => $defaultProcessor, |
||
69 | ])); |
||
70 | |||
71 | $requiredData->addChild($this->getElement('checkbox', [ |
||
72 | 'name' => 'enabled', |
||
73 | 'label' => 'common.label.enabled', |
||
74 | ])); |
||
75 | |||
76 | $requiredData->addChild($this->getElement('text_field', [ |
||
77 | 'name' => 'hierarchy', |
||
78 | 'label' => 'common.label.hierarchy', |
||
79 | 'rules' => [ |
||
80 | $this->getRule('required'), |
||
81 | ], |
||
82 | ])); |
||
83 | |||
84 | $clientGroupData = $form->addChild($this->getElement('nested_fieldset', [ |
||
85 | 'name' => 'client_group_data', |
||
86 | 'label' => 'payment_method.fieldset.client_groups', |
||
87 | ])); |
||
88 | |||
89 | $clientGroupData->addChild($this->getElement('tip', [ |
||
90 | 'tip' => 'payment_method.tip.client_groups', |
||
91 | ])); |
||
92 | |||
93 | $clientGroupData->addChild($this->getElement('multi_select', [ |
||
94 | 'name' => 'clientGroups', |
||
95 | 'label' => 'payment_method.label.client_groups', |
||
96 | 'options' => $this->get('client_group.dataset.admin')->getResult('select'), |
||
97 | 'transformer' => $this->getRepositoryTransformer('collection', $this->get('client_group.repository')), |
||
98 | ])); |
||
99 | |||
100 | $statusesData = $form->addChild($this->getElement('nested_fieldset', [ |
||
101 | 'name' => 'statuses', |
||
102 | 'label' => 'payment_method.fieldset.order_statuses', |
||
103 | ])); |
||
104 | |||
105 | $statusesData->addChild($this->getElement('select', [ |
||
106 | 'name' => 'paymentPendingOrderStatus', |
||
107 | 'label' => 'payment_method.label.payment_pending_order_status', |
||
108 | 'options' => $orderStatuses, |
||
109 | 'transformer' => $this->getRepositoryTransformer('entity', $this->get('order_status.repository')), |
||
110 | ])); |
||
111 | |||
112 | $statusesData->addChild($this->getElement('select', [ |
||
113 | 'name' => 'paymentSuccessOrderStatus', |
||
114 | 'label' => 'payment_method.label.payment_success_order_status', |
||
115 | 'options' => $orderStatuses, |
||
116 | 'transformer' => $this->getRepositoryTransformer('entity', $this->get('order_status.repository')), |
||
117 | ])); |
||
118 | |||
119 | $statusesData->addChild($this->getElement('select', [ |
||
120 | 'name' => 'paymentFailureOrderStatus', |
||
121 | 'label' => 'payment_method.label.payment_failure_order_status', |
||
122 | 'options' => $orderStatuses, |
||
123 | 'transformer' => $this->getRepositoryTransformer('entity', $this->get('order_status.repository')), |
||
124 | ])); |
||
125 | |||
126 | $shippingMethodsData = $form->addChild($this->getElement('nested_fieldset', [ |
||
127 | 'name' => 'shipping_methods_data', |
||
128 | 'label' => 'payment_method.fieldset.shipping_methods', |
||
129 | ])); |
||
130 | |||
131 | $shippingMethodsData->addChild($this->getElement('multi_select', [ |
||
132 | 'name' => 'shippingMethods', |
||
133 | 'label' => 'payment_method.label.shipping_methods', |
||
134 | 'options' => $this->get('shipping_method.dataset.admin')->getResult('select'), |
||
135 | 'transformer' => $this->getRepositoryTransformer('collection', $this->get('shipping_method.repository')), |
||
136 | ])); |
||
137 | |||
138 | $configurationData = $form->addChild($this->getElement('nested_fieldset', [ |
||
139 | 'name' => 'configuration', |
||
140 | 'property_path' => new PropertyPath('configuration'), |
||
141 | 'label' => 'payment_method.fieldset.processor_configuration', |
||
142 | ])); |
||
143 | |||
144 | foreach ($processors->all() as $processor) { |
||
145 | |||
146 | $dependency = $this->getDependency('show', [ |
||
147 | 'form' => $form, |
||
148 | 'field' => $processorType, |
||
149 | 'condition' => new Equals($processor->getConfigurator()->getName()), |
||
150 | ]); |
||
151 | |||
152 | $processor->getConfigurator()->addConfigurationFields($this, $configurationData, $dependency); |
||
153 | } |
||
154 | |||
155 | $this->addShopsFieldset($form); |
||
156 | |||
157 | $form->addFilter($this->getFilter('no_code')); |
||
158 | $form->addFilter($this->getFilter('trim')); |
||
159 | $form->addFilter($this->getFilter('secure')); |
||
160 | } |
||
161 | |||
167 |