ClientAddressBookFormBuilder::buildForm()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 118
Code Lines 73

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 118
c 0
b 0
f 0
rs 8.2857
cc 1
eloc 73
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
namespace WellCommerce\Bundle\AppBundle\Form\Front;
13
14
use WellCommerce\Bundle\CoreBundle\Form\AbstractFormBuilder;
15
use WellCommerce\Component\Form\Elements\FormInterface;
16
17
/**
18
 * Class ClientAddressBookFormBuilder
19
 *
20
 * @author  Adam Piotrowski <[email protected]>
21
 */
22
class ClientAddressBookFormBuilder extends AbstractFormBuilder
23
{
24
    public function getAlias(): string
25
    {
26
        return 'front.client_address_book';
27
    }
28
    
29
    public function buildForm(FormInterface $form)
30
    {
31
        $countries      = $this->get('country.repository')->all();
32
        $defaultCountry = $this->getShopStorage()->getCurrentShop()->getDefaultCountry();
33
34
        $billingAddress = $form->addChild($this->getElement('nested_fieldset', [
35
            'name'  => 'billingAddress',
36
            'label' => 'client.heading.billing_address',
37
        ]));
38
39
        $billingAddress->addChild($this->getElement('text_field', [
40
            'name'  => 'billingAddress.firstName',
41
            'label' => 'client.label.address.first_name',
42
        ]));
43
44
        $billingAddress->addChild($this->getElement('text_field', [
45
            'name'  => 'billingAddress.lastName',
46
            'label' => 'client.label.address.last_name',
47
        ]));
48
49
        $billingAddress->addChild($this->getElement('text_field', [
50
            'name'  => 'billingAddress.companyName',
51
            'label' => 'client.label.address.company_name',
52
        ]));
53
54
        $billingAddress->addChild($this->getElement('text_field', [
55
            'name'  => 'billingAddress.vatId',
56
            'label' => 'client.label.address.vat_id',
57
        ]));
58
59
        $billingAddress->addChild($this->getElement('text_field', [
60
            'name'  => 'billingAddress.line1',
61
            'label' => 'client.label.address.line1',
62
        ]));
63
64
        $billingAddress->addChild($this->getElement('text_field', [
65
            'name'  => 'billingAddress.line2',
66
            'label' => 'client.label.address.line2',
67
        ]));
68
69
        $billingAddress->addChild($this->getElement('text_field', [
70
            'name'  => 'billingAddress.postalCode',
71
            'label' => 'client.label.address.postal_code',
72
        ]));
73
74
        $billingAddress->addChild($this->getElement('text_field', [
75
            'name'  => 'billingAddress.state',
76
            'label' => 'client.label.address.state',
77
        ]));
78
79
        $billingAddress->addChild($this->getElement('text_field', [
80
            'name'  => 'billingAddress.city',
81
            'label' => 'client.label.address.city',
82
        ]));
83
84
        $billingAddress->addChild($this->getElement('select', [
85
            'name'    => 'billingAddress.country',
86
            'label'   => 'client.label.address.country',
87
            'options' => $countries,
88
            'default' => $defaultCountry
89
        ]));
90
91
        $shippingAddress = $form->addChild($this->getElement('nested_fieldset', [
92
            'name'  => 'shippingAddress',
93
            'label' => 'client.heading.shipping_address',
94
        ]));
95
96
        $shippingAddress->addChild($this->getElement('text_field', [
97
            'name'  => 'shippingAddress.firstName',
98
            'label' => 'client.label.address.first_name',
99
        ]));
100
101
        $shippingAddress->addChild($this->getElement('text_field', [
102
            'name'  => 'shippingAddress.lastName',
103
            'label' => 'client.label.address.last_name',
104
        ]));
105
    
106
        $shippingAddress->addChild($this->getElement('text_field', [
107
            'name'  => 'shippingAddress.companyName',
108
            'label' => 'client.label.address.company_name',
109
        ]));
110
        
111
        $shippingAddress->addChild($this->getElement('text_field', [
112
            'name'  => 'shippingAddress.line1',
113
            'label' => 'client.label.address.line1',
114
        ]));
115
116
        $shippingAddress->addChild($this->getElement('text_field', [
117
            'name'  => 'shippingAddress.line2',
118
            'label' => 'client.label.address.line2',
119
        ]));
120
121
        $shippingAddress->addChild($this->getElement('text_field', [
122
            'name'  => 'shippingAddress.postalCode',
123
            'label' => 'client.label.address.postal_code',
124
        ]));
125
126
        $shippingAddress->addChild($this->getElement('text_field', [
127
            'name'  => 'shippingAddress.province',
128
            'label' => 'client.label.address.province',
129
        ]));
130
131
        $shippingAddress->addChild($this->getElement('text_field', [
132
            'name'  => 'shippingAddress.city',
133
            'label' => 'client.label.address.city',
134
        ]));
135
136
        $shippingAddress->addChild($this->getElement('select', [
137
            'name'    => 'shippingAddress.country',
138
            'label'   => 'client.label.address.country',
139
            'options' => $countries,
140
            'default' => $defaultCountry
141
        ]));
142
143
        $form->addFilter($this->getFilter('no_code'));
144
        $form->addFilter($this->getFilter('trim'));
145
        $form->addFilter($this->getFilter('secure'));
146
    }
147
}
148