Completed
Push — master ( a54a4b...bbfdca )
by Adam
15:54
created

ClientGroupFormBuilder::buildForm()   A

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 67
Code Lines 43

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 9.2815
c 0
b 0
f 0
cc 1
eloc 43
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 <adam@wellcommerce.org>
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\Admin;
13
14
use WellCommerce\Bundle\CoreBundle\Form\AbstractFormBuilder;
15
use WellCommerce\Component\Form\Elements\FormInterface;
16
17
/**
18
 * Class ClientGroupFormBuilder
19
 *
20
 * @author  Adam Piotrowski <adam@wellcommerce.org>
21
 */
22
class ClientGroupFormBuilder extends AbstractFormBuilder
23
{
24
    public function getAlias(): string
25
    {
26
        return 'admin.client_group';
27
    }
28
    
29
    public function buildForm(FormInterface $form)
30
    {
31
        $requiredData = $form->addChild($this->getElement('nested_fieldset', [
32
            'name'  => 'required_data',
33
            'label' => 'common.fieldset.general',
34
        ]));
35
        
36
        $languageData = $requiredData->addChild($this->getElement('language_fieldset', [
37
            'name'        => 'translations',
38
            'label'       => 'common.fieldset.translations',
39
            'transformer' => $this->getRepositoryTransformer('translation', $this->get('client_group.repository')),
40
        ]));
41
        
42
        $languageData->addChild($this->getElement('text_field', [
43
            'name'  => 'name',
44
            'label' => 'common.label.name',
45
            'rules' => [
46
                $this->getRule('required'),
47
            ],
48
        ]));
49
        
50
        $discountSettings = $form->addChild($this->getElement('nested_fieldset', [
51
            'name'  => 'discount_data',
52
            'label' => 'common.fieldset.discount_settings',
53
        ]));
54
        
55
        $discountSettings->addChild($this->getElement('tip', [
56
            'tip' => 'common.tip.discount_expression',
57
        ]));
58
        
59
        $discountSettings->addChild($this->getElement('text_field', [
60
            'name'   => 'discount',
61
            'label'  => 'common.label.discount',
62
            'suffix' => '%',
63
        ]));
64
        
65
        $minimumOrderAmount = $form->addChild($this->getElement('nested_fieldset', [
66
            'name'  => 'minimumOrderAmount',
67
            'label' => 'common.fieldset.minimum_order_amount',
68
        ]));
69
        
70
        $minimumOrderAmount->addChild($this->getElement('text_field', [
71
            'name'    => 'minimumOrderAmount.value',
72
            'label'   => 'common.label.minimum_order_amount.value',
73
            'suffix'  => '%',
74
            'filters' => [
75
                $this->getFilter('comma_to_dot_changer'),
76
            ],
77
            'rules'   => [
78
                $this->getRule('required'),
79
            ],
80
            'default' => 0,
81
        ]));
82
        
83
        $minimumOrderAmount->addChild($this->getElement('select', [
84
            'name'    => 'minimumOrderAmount.currency',
85
            'label'   => 'common.label.minimum_order_amount.currency',
86
            'options' => $this->get('currency.dataset.admin')->getResult('select', ['order_by' => 'code'], [
87
                'label_column' => 'code',
88
                'value_column' => 'code',
89
            ]),
90
        ]));
91
        
92
        $form->addFilter($this->getFilter('no_code'));
93
        $form->addFilter($this->getFilter('trim'));
94
        $form->addFilter($this->getFilter('secure'));
95
    }
96
}
97