SchedulesForm::buildForm()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 73

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 73
rs 8.589
c 0
b 0
f 0
cc 1
nc 1
nop 0

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
/*      This file is part of the Thelia package.                                     */
4
/*                                                                                   */
5
/*      Copyright (c) OpenStudio                                                     */
6
/*      email : [email protected]                                                       */
7
/*      web : http://www.thelia.net                                                  */
8
/*                                                                                   */
9
/*      For the full copyright and license information, please view the LICENSE.txt  */
10
/*      file that was distributed with this source code.                             */
11
/*************************************************************************************/
12
/*************************************************************************************/
13
14
namespace Dealer\Form;
15
16
use Dealer\Dealer;
17
use Symfony\Component\Validator\Constraints\NotBlank;
18
use Thelia\Form\BaseForm;
19
20
/**
21
 * Class SchedulesForm
22
 * @package Dealer\Form
23
 */
24
class SchedulesForm extends BaseForm
25
{
26
27
    /**
28
     *
29
     * in this function you add all the fields you need for your Form.
30
     * Form this you have to call add method on $this->formBuilder attribute :
31
     *
32
     * $this->formBuilder->add("name", "text")
33
     *   ->add("email", "email", array(
34
     *           "attr" => array(
35
     *               "class" => "field"
36
     *           ),
37
     *           "label" => "email",
38
     *           "constraints" => array(
39
     *               new \Symfony\Component\Validator\Constraints\NotBlank()
40
     *           )
41
     *       )
42
     *   )
43
     *   ->add('age', 'integer');
44
     *
45
     * @return null
46
     */
47
    protected function buildForm()
48
    {
49
        $this->formBuilder
50
            ->add("day", "choice", [
51
                "choices" => $this->getDay(),
52
                "label" => $this->translator->trans("Day", [], Dealer::MESSAGE_DOMAIN),
53
                "label_attr" => ["for" => "attr-dealer-schedules-day"],
54
                "required" => false,
55
                "multiple" => true,
56
                "attr" => array()
57
            ])
58
            ->add("beginAM", "time", [
59
                "label" => $this->translator->trans("Begin", [], Dealer::MESSAGE_DOMAIN),
60
                "label_attr" => ["for" => "attr-dealer-schedules-begin"],
61
                "input" => "string",
62
                "widget" => "single_text",
63
                "required" => false,
64
                "attr" => array()
65
            ])
66
            ->add("endAM", "time", [
67
                "label" => $this->translator->trans("End", [], Dealer::MESSAGE_DOMAIN),
68
                "label_attr" => ["for" => "attr-dealer-schedules-end"],
69
                "input" => "string",
70
                "widget" => "single_text",
71
                "required" => false,
72
                "attr" => array()
73
            ])
74
            ->add("beginPM", "time", [
75
                "label" => $this->translator->trans("Begin", [], Dealer::MESSAGE_DOMAIN),
76
                "label_attr" => ["for" => "attr-dealer-schedules-beginPM"],
77
                "input" => "string",
78
                "widget" => "single_text",
79
                "required" => false,
80
                "attr" => array()
81
            ])
82
            ->add("endPM", "time", [
83
                "label" => $this->translator->trans("End", [], Dealer::MESSAGE_DOMAIN),
84
                "label_attr" => ["for" => "attr-dealer-schedules-endPM"],
85
                "input" => "string",
86
                "widget" => "single_text",
87
                "required" => false,
88
                "attr" => array()
89
            ])
90
            ->add("period_begin", "date", [
91
                "label" => $this->translator->trans("Period Begin", [], Dealer::MESSAGE_DOMAIN),
92
                "label_attr" => ["for" => "attr-dealer-schedules-period-begin"],
93
                "input" => "string",
94
                "widget" => "single_text",
95
                "required" => false,
96
                "attr" => array()
97
            ])
98
            ->add("period_end", "date", [
99
                "label" => $this->translator->trans("Period End", [], Dealer::MESSAGE_DOMAIN),
100
                "label_attr" => ["for" => "attr-dealer-schedules-period-end"],
101
                "input" => "string",
102
                "widget" => "single_text",
103
                "required" => false,
104
                "attr" => array()
105
            ])
106
            ->add("closed", "integer", [
107
                "label" => $this->translator->trans("Closed", [], Dealer::MESSAGE_DOMAIN),
108
                "label_attr" => ["for" => "attr-dealer-schedules-closed"],
109
                "required" => true,
110
                "attr" => array()
111
            ])
112
            ->add('dealer_id', 'integer', array(
113
                "label" => $this->translator->trans("Dealer", [], Dealer::MESSAGE_DOMAIN),
114
                "label_attr" => ["for" => "attr-dealer-schedules-dealer_id"],
115
                "required" => true,
116
                "constraints" => array(new NotBlank(), ),
117
                "attr" => array()
118
            ));
119
    }
120
121
    protected function getDay()
122
    {
123
        return [
124
            $this->translator->trans("Monday", [], Dealer::MESSAGE_DOMAIN),
125
            $this->translator->trans("Tuesday", [], Dealer::MESSAGE_DOMAIN),
126
            $this->translator->trans("Wednesday", [], Dealer::MESSAGE_DOMAIN),
127
            $this->translator->trans("Thursday", [], Dealer::MESSAGE_DOMAIN),
128
            $this->translator->trans("Friday", [], Dealer::MESSAGE_DOMAIN),
129
            $this->translator->trans("Saturday", [], Dealer::MESSAGE_DOMAIN),
130
            $this->translator->trans("Sunday", [], Dealer::MESSAGE_DOMAIN)
131
        ];
132
    }
133
134
    public function getName()
135
    {
136
        return "schedules_create";
137
    }
138
}
139