SupportedTypes   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 226
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 2
eloc 136
c 5
b 0
f 0
dl 0
loc 226
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDefaultTypeConfig() 0 7 2
1
<?php
2
3
namespace Micayael\Bundle\FormGeneratorBundle\Config;
4
5
use Micayael\Bundle\FormGeneratorBundle\Exception\NotSupportedFormTypeException;
6
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
7
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
8
use Symfony\Component\Form\Extension\Core\Type\CountryType;
9
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
10
use Symfony\Component\Form\Extension\Core\Type\DateType;
11
use Symfony\Component\Form\Extension\Core\Type\EmailType;
12
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
13
use Symfony\Component\Form\Extension\Core\Type\LanguageType;
14
use Symfony\Component\Form\Extension\Core\Type\LocaleType;
15
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
16
use Symfony\Component\Form\Extension\Core\Type\NumberType;
17
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
18
use Symfony\Component\Form\Extension\Core\Type\PercentType;
19
use Symfony\Component\Form\Extension\Core\Type\TelType;
20
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
21
use Symfony\Component\Form\Extension\Core\Type\TextType;
22
use Symfony\Component\Form\Extension\Core\Type\TimeType;
23
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
24
use Symfony\Component\Form\Extension\Core\Type\UrlType;
25
use Symfony\Component\Form\Extension\Core\Type\UuidType;
26
27
class SupportedTypes
28
{
29
    public const SUPPORTED_TYPES = [
30
        // Texts
31
        'text' => [
32
            'class' => TextType::class,
33
            'default_options' => [
34
                'constraints' => [
35
                    'not_blank' => [],
36
                ],
37
            ],
38
        ],
39
        'textarea' => [
40
            'class' => TextareaType::class,
41
            'default_options' => [
42
                'constraints' => [
43
                    'not_blank' => [],
44
                ],
45
            ],
46
        ],
47
        'email' => [
48
            'class' => EmailType::class,
49
            'default_options' => [
50
                'constraints' => [
51
                    'not_blank' => [],
52
                    'email' => [],
53
                ],
54
            ],
55
        ],
56
        'password' => [
57
            'class' => PasswordType::class,
58
            'default_options' => [
59
                'constraints' => [
60
                    'not_blank' => [],
61
                ],
62
            ],
63
        ],
64
        'url' => [
65
            'class' => UrlType::class,
66
            'default_options' => [
67
                'constraints' => [
68
                    'not_blank' => [],
69
                    'url' => [],
70
                ],
71
            ],
72
        ],
73
        'tel' => [
74
            'class' => TelType::class,
75
            'default_options' => [
76
                'constraints' => [
77
                    'not_blank' => [],
78
                ],
79
            ],
80
        ],
81
        'uuid' => [
82
            'class' => UuidType::class,
83
            'default_options' => [
84
                'constraints' => [
85
                    'not_blank' => [],
86
                ],
87
            ],
88
        ],
89
90
        // Numbers
91
        'integer' => [
92
            'class' => IntegerType::class,
93
            'default_options' => [
94
                'constraints' => [
95
                    'not_blank' => [],
96
                    'type' => [
97
                        'type' => 'integer',
98
                    ],
99
                ],
100
            ],
101
        ],
102
        'money' => [
103
            'class' => MoneyType::class,
104
            'default_options' => [
105
                'constraints' => [
106
                    'not_blank' => [],
107
                    'type' => [
108
                        'type' => 'numeric',
109
                    ],
110
                ],
111
            ],
112
        ],
113
        'number' => [
114
            'class' => NumberType::class,
115
            'default_options' => [
116
                'constraints' => [
117
                    'not_blank' => [],
118
                    'type' => [
119
                        'type' => 'numeric',
120
                    ],
121
                ],
122
            ],
123
        ],
124
        'percent' => [
125
            'class' => PercentType::class,
126
            'default_options' => [
127
                'constraints' => [
128
                    'not_blank' => [],
129
                    'type' => [
130
                        'type' => 'numeric',
131
                    ],
132
                ],
133
            ],
134
        ],
135
136
        // Choices
137
        'choice' => [
138
            'class' => ChoiceType::class,
139
            'default_options' => [
140
                'constraints' => [
141
                    'not_blank' => [],
142
                ],
143
            ],
144
        ],
145
        'country' => [
146
            'class' => CountryType::class,
147
            'default_options' => [
148
                'constraints' => [
149
                    'not_blank' => [],
150
                ],
151
            ],
152
        ],
153
        'language' => [
154
            'class' => LanguageType::class,
155
            'default_options' => [
156
                'constraints' => [
157
                    'not_blank' => [],
158
                ],
159
            ],
160
        ],
161
        'locale' => [
162
            'class' => LocaleType::class,
163
            'default_options' => [
164
                'constraints' => [
165
                    'not_blank' => [],
166
                ],
167
            ],
168
        ],
169
        'timezone' => [
170
            'class' => TimezoneType::class,
171
            'default_options' => [
172
                'constraints' => [
173
                    'not_blank' => [],
174
                ],
175
            ],
176
        ],
177
        'currency' => [
178
            'class' => CurrencyType::class,
179
            'default_options' => [
180
                'constraints' => [
181
                    'not_blank' => [],
182
                ],
183
            ],
184
        ],
185
186
        // Dates
187
        'date' => [
188
            'class' => DateType::class,
189
            'default_options' => [
190
                'input' => 'string',
191
                'widget' => 'single_text',
192
//                'format' => 'dd/MM/yyyy',
193
//                'attr' => [
194
//                    'placeholder' => 'dd/mm/aaaa',
195
//                ]
196
                'constraints' => [
197
                    'not_blank' => [],
198
                    'date' => [],
199
                ],
200
            ],
201
        ],
202
        'time' => [
203
            'class' => TimeType::class,
204
            'default_options' => [
205
                'input' => 'string',
206
                'widget' => 'single_text',
207
                'with_seconds' => false,
208
                'constraints' => [
209
                    'not_blank' => [],
210
                    'time' => [],
211
                ],
212
            ],
213
        ],
214
215
        // Special types
216
        'boolean' => [
217
            'class' => CheckboxType::class,
218
            'default_options' => [
219
                'required' => false,
220
                'constraints' => [
221
                    'type' => [
222
                        'type' => 'boolean',
223
                        'message' => 'The value {{ value }} is not a valid {{ type }}.',
224
                    ],
225
                ],
226
            ],
227
        ],
228
        'boolean_choice' => [
229
            'class' => ChoiceType::class,
230
            'default_options' => [
231
                'required' => false,
232
                'choices' => [
233
                    'Si' => true,
234
                    'No' => false,
235
                ],
236
                'constraints' => [
237
                    'type' => [
238
                        'type' => 'boolean',
239
                        'message' => 'The value {{ value }} is not a valid {{ type }}.',
240
                    ],
241
                ],
242
            ],
243
        ],
244
    ];
245
246
    public static function getDefaultTypeConfig(string $inputType): array
247
    {
248
        if (!isset(self::SUPPORTED_TYPES[$inputType])) {
249
            throw new NotSupportedFormTypeException($inputType);
250
        }
251
252
        return self::SUPPORTED_TYPES[$inputType];
253
    }
254
}
255