Completed
Push — master ( 63d470...84e35a )
by Adam
18:27
created

InvoiceFormBuilder::buildForm()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 155
Code Lines 97

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 155
rs 8.2857
c 0
b 0
f 0
cc 1
eloc 97
nc 1
nop 1

How to fix   Long Method   

Long Method

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:

1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\InvoiceBundle\Form\Admin;
14
15
use WellCommerce\Bundle\CoreBundle\Form\AbstractFormBuilder;
16
use WellCommerce\Component\Form\DataTransformer\DateTransformer;
17
use WellCommerce\Component\Form\Elements\FormInterface;
18
19
/**
20
 * Class InvoiceFormBuilder
21
 *
22
 * @author  Adam Piotrowski <[email protected]>
23
 */
24
class InvoiceFormBuilder extends AbstractFormBuilder
25
{
26
    public function getAlias(): string
27
    {
28
        return 'admin.invoice';
29
    }
30
    
31
    public function buildForm(FormInterface $form)
32
    {
33
        $countries = $this->get('country.repository')->all();
34
        
35
        $requiredData = $form->addChild($this->getElement('nested_fieldset', [
36
            'name'  => 'required_data',
37
            'label' => 'common.fieldset.general',
38
        ]));
39
        
40
        $requiredData->addChild($this->getElement('text_field', [
41
            'name'  => 'amountDue',
42
            'label' => 'invoice.label.amount_due',
43
            'rules' => [
44
                $this->getRule('required'),
45
            ],
46
        ]));
47
        
48
        $requiredData->addChild($this->getElement('text_field', [
49
            'name'  => 'amountPaid',
50
            'label' => 'invoice.label.amount_paid',
51
            'rules' => [
52
                $this->getRule('required'),
53
            ],
54
        ]));
55
    
56
        $requiredData->addChild($this->getElement('checkbox', [
57
            'name'  => 'paid',
58
            'label' => 'invoice.label.paid',
59
        ]));
60
        
61
        $requiredData->addChild($this->getElement('date', [
62
            'name'        => 'date',
63
            'label'       => 'invoice.label.date',
64
            'transformer' => new DateTransformer('Y-m-d'),
65
            'rules' => [
66
                $this->getRule('required'),
67
            ],
68
        ]));
69
        
70
        $requiredData->addChild($this->getElement('date', [
71
            'name'        => 'dueDate',
72
            'label'       => 'invoice.label.due_date',
73
            'transformer' => new DateTransformer('Y-m-d'),
74
            'rules' => [
75
                $this->getRule('required'),
76
            ],
77
        ]));
78
        
79
        $requiredData->addChild($this->getElement('text_field', [
80
            'name'  => 'amountPaid',
81
            'label' => 'invoice.label.amount_paid',
82
            'rules' => [
83
                $this->getRule('required'),
84
            ],
85
        ]));
86
        
87
        $requiredData->addChild($this->getElement('text_field', [
88
            'name'  => 'shippingMethodName',
89
            'label' => 'invoice.label.shipping_method_name',
90
            'rules' => [
91
                $this->getRule('required'),
92
            ],
93
        ]));
94
        
95
        $requiredData->addChild($this->getElement('text_field', [
96
            'name'  => 'paymentMethodName',
97
            'label' => 'invoice.label.payment_method_name',
98
            'rules' => [
99
                $this->getRule('required'),
100
            ],
101
        ]));
102
    
103
        $requiredData->addChild($this->getElement('text_field', [
104
            'name'  => 'signature',
105
            'label' => 'invoice.label.signature',
106
            'rules' => [
107
                $this->getRule('required'),
108
            ],
109
        ]));
110
        
111
        $billingAddress = $form->addChild($this->getElement('nested_fieldset', [
112
            'name'  => 'billingAddress',
113
            'label' => 'client.heading.billing_address',
114
        ]));
115
        
116
        $billingAddress->addChild($this->getElement('text_field', [
117
            'name'  => 'billingAddress.firstName',
118
            'label' => 'client.label.address.first_name',
119
            'rules' => [
120
                $this->getRule('required'),
121
            ],
122
        ]));
123
        
124
        $billingAddress->addChild($this->getElement('text_field', [
125
            'name'  => 'billingAddress.lastName',
126
            'label' => 'client.label.address.last_name',
127
            'rules' => [
128
                $this->getRule('required'),
129
            ],
130
        ]));
131
        
132
        $billingAddress->addChild($this->getElement('text_field', [
133
            'name'  => 'billingAddress.line1',
134
            'label' => 'client.label.address.line1',
135
            'rules' => [
136
                $this->getRule('required'),
137
            ],
138
        ]));
139
        
140
        $billingAddress->addChild($this->getElement('text_field', [
141
            'name'  => 'billingAddress.line2',
142
            'label' => 'client.label.address.line2',
143
        ]));
144
        
145
        $billingAddress->addChild($this->getElement('text_field', [
146
            'name'  => 'billingAddress.postalCode',
147
            'label' => 'client.label.address.postal_code',
148
            'rules' => [
149
                $this->getRule('required'),
150
            ],
151
        ]));
152
        
153
        $billingAddress->addChild($this->getElement('text_field', [
154
            'name'  => 'billingAddress.state',
155
            'label' => 'client.label.address.state',
156
        ]));
157
        
158
        $billingAddress->addChild($this->getElement('text_field', [
159
            'name'  => 'billingAddress.city',
160
            'label' => 'client.label.address.city',
161
            'rules' => [
162
                $this->getRule('required'),
163
            ],
164
        ]));
165
        
166
        $billingAddress->addChild($this->getElement('select', [
167
            'name'    => 'billingAddress.country',
168
            'label'   => 'client.label.address.country',
169
            'options' => $countries,
170
        ]));
171
        
172
        $billingAddress->addChild($this->getElement('text_field', [
173
            'name'  => 'billingAddress.vatId',
174
            'label' => 'client.label.address.vat_id',
175
        ]));
176
        
177
        $billingAddress->addChild($this->getElement('text_field', [
178
            'name'  => 'billingAddress.companyName',
179
            'label' => 'client.label.address.company_name',
180
        ]));
181
        
182
        $form->addFilter($this->getFilter('no_code'));
183
        $form->addFilter($this->getFilter('trim'));
184
        $form->addFilter($this->getFilter('secure'));
185
    }
186
}
187