Passed
Push — master ( 6cc728...616f18 )
by Juan
10:31
created
src/Service/FormGenerator.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
         $this->formFactory = $formFactory;
24 24
     }
25 25
 
26
-    public function createFormFromYaml(string $formConfigYaml, array $formOptions = [], $data = null, string $baseFormTypeClass = null, string $groupName = null): ?FormInterface
26
+    public function createFormFromYaml(string $formConfigYaml, array $formOptions = [ ], $data = null, string $baseFormTypeClass = null, string $groupName = null): ?FormInterface
27 27
     {
28 28
         $array = Yaml::parse($formConfigYaml);
29 29
         $json = json_encode($array);
@@ -31,14 +31,14 @@  discard block
 block discarded – undo
31 31
         return $this->createFormFromJson($json, $formOptions, $data, $baseFormTypeClass, $groupName);
32 32
     }
33 33
 
34
-    public function createFormFromJson(string $formConfigJson, array $formOptions = [], $data = null, string $baseFormTypeClass = null, string $groupName = null): ?FormInterface
34
+    public function createFormFromJson(string $formConfigJson, array $formOptions = [ ], $data = null, string $baseFormTypeClass = null, string $groupName = null): ?FormInterface
35 35
     {
36 36
         $formConfig = json_decode($formConfigJson, true);
37 37
 
38 38
         return $this->createForm($formConfig, $formOptions, $data, $baseFormTypeClass, $groupName);
39 39
     }
40 40
 
41
-    public function createForm(array $formConfig, array $formOptions = [], $data = null, string $baseFormTypeClass = null, string $groupName = null): ?FormInterface
41
+    public function createForm(array $formConfig, array $formOptions = [ ], $data = null, string $baseFormTypeClass = null, string $groupName = null): ?FormInterface
42 42
     {
43 43
         if (empty($formConfig)) {
44 44
             return null;
@@ -53,34 +53,34 @@  discard block
 block discarded – undo
53 53
         }
54 54
 
55 55
         foreach ($formConfig as $inputName => $inputConfig) {
56
-            $inputType = isset($inputConfig['type']) ? $inputConfig['type'] : 'text';
56
+            $inputType = isset($inputConfig[ 'type' ]) ? $inputConfig[ 'type' ] : 'text';
57 57
 
58 58
             // Se obtiene la configuración predeterminada
59 59
             if (class_exists($inputType)) {
60 60
                 $inputDefaultConfig = [
61 61
                     'class' => $inputType,
62
-                    'default_options' => [],
62
+                    'default_options' => [ ],
63 63
                 ];
64 64
             } else {
65 65
                 $inputDefaultConfig = SupportedTypes::getDefaultTypeConfig($inputType);
66 66
             }
67 67
 
68 68
             // se obtienen las opciones definidas para este input
69
-            $inputOptions = isset($inputConfig['options']) ? $inputConfig['options'] : [];
69
+            $inputOptions = isset($inputConfig[ 'options' ]) ? $inputConfig[ 'options' ] : [ ];
70 70
 
71
-            $inputOptions['constraints'] = $this->getConstraints($inputType, $inputDefaultConfig['default_options'], $inputOptions);
71
+            $inputOptions[ 'constraints' ] = $this->getConstraints($inputType, $inputDefaultConfig[ 'default_options' ], $inputOptions);
72 72
 
73 73
             // Se compilan las opciones default con las definidas
74 74
             $inputOptions = array_merge(
75
-                $inputDefaultConfig['default_options'],
75
+                $inputDefaultConfig[ 'default_options' ],
76 76
                 $inputOptions
77 77
             );
78 78
 
79 79
             // Se crea el input de formulario
80 80
             if ($groupName) {
81
-                $form->get($groupName)->add($inputName, $inputDefaultConfig['class'], $inputOptions);
81
+                $form->get($groupName)->add($inputName, $inputDefaultConfig[ 'class' ], $inputOptions);
82 82
             } else {
83
-                $form->add($inputName, $inputDefaultConfig['class'], $inputOptions);
83
+                $form->add($inputName, $inputDefaultConfig[ 'class' ], $inputOptions);
84 84
             }
85 85
         }
86 86
 
@@ -89,31 +89,31 @@  discard block
 block discarded – undo
89 89
 
90 90
     private function getConstraints(string $inputType, array $inputDefaultOptions, array $inputOptions)
91 91
     {
92
-        $ret = [];
92
+        $ret = [ ];
93 93
 
94
-        $validations = isset($inputDefaultOptions['constraints']) ? $inputDefaultOptions['constraints'] : [];
95
-        $validations = array_merge($validations, isset($inputOptions['constraints']) ? $inputOptions['constraints'] : []);
94
+        $validations = isset($inputDefaultOptions[ 'constraints' ]) ? $inputDefaultOptions[ 'constraints' ] : [ ];
95
+        $validations = array_merge($validations, isset($inputOptions[ 'constraints' ]) ? $inputOptions[ 'constraints' ] : [ ]);
96 96
 
97 97
         foreach ($validations as $validation => $validationOptions) {
98 98
             switch ($validation) {
99 99
                 case 'not_blank':
100
-                    if (isset($inputOptions['required']) && false === $inputOptions['required']) {
100
+                    if (isset($inputOptions[ 'required' ]) && false === $inputOptions[ 'required' ]) {
101 101
                         // no se setea la validación
102 102
                     } else {
103
-                        $ret[] = new NotBlank($validationOptions);
103
+                        $ret[ ] = new NotBlank($validationOptions);
104 104
                     }
105 105
                     break;
106 106
                 case 'email':
107
-                    $ret[] = new Email($validationOptions);
107
+                    $ret[ ] = new Email($validationOptions);
108 108
                     break;
109 109
                 case 'url':
110
-                    $ret[] = new Url($validationOptions);
110
+                    $ret[ ] = new Url($validationOptions);
111 111
                     break;
112 112
                 case 'length':
113
-                    $ret[] = new Length($validationOptions);
113
+                    $ret[ ] = new Length($validationOptions);
114 114
                     break;
115 115
                 case 'date':
116
-                    $ret[] = new Date($validationOptions);
116
+                    $ret[ ] = new Date($validationOptions);
117 117
                     break;
118 118
             }
119 119
         }
Please login to merge, or discard this patch.
src/Config/SupportedTypes.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
             'class' => TextType::class,
33 33
             'default_options' => [
34 34
                 'constraints' => [
35
-                    'not_blank' => [],
35
+                    'not_blank' => [ ],
36 36
                 ],
37 37
             ],
38 38
         ],
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
             'class' => TextareaType::class,
41 41
             'default_options' => [
42 42
                 'constraints' => [
43
-                    'not_blank' => [],
43
+                    'not_blank' => [ ],
44 44
                 ],
45 45
             ],
46 46
         ],
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
             'class' => EmailType::class,
49 49
             'default_options' => [
50 50
                 'constraints' => [
51
-                    'not_blank' => [],
52
-                    'email' => [],
51
+                    'not_blank' => [ ],
52
+                    'email' => [ ],
53 53
                 ],
54 54
             ],
55 55
         ],
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
             'class' => PasswordType::class,
58 58
             'default_options' => [
59 59
                 'constraints' => [
60
-                    'not_blank' => [],
60
+                    'not_blank' => [ ],
61 61
                 ],
62 62
             ],
63 63
         ],
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
             'class' => UrlType::class,
66 66
             'default_options' => [
67 67
                 'constraints' => [
68
-                    'not_blank' => [],
69
-                    'url' => [],
68
+                    'not_blank' => [ ],
69
+                    'url' => [ ],
70 70
                 ],
71 71
             ],
72 72
         ],
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
             'class' => TelType::class,
75 75
             'default_options' => [
76 76
                 'constraints' => [
77
-                    'not_blank' => [],
77
+                    'not_blank' => [ ],
78 78
                 ],
79 79
             ],
80 80
         ],
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             'class' => UuidType::class,
83 83
             'default_options' => [
84 84
                 'constraints' => [
85
-                    'not_blank' => [],
85
+                    'not_blank' => [ ],
86 86
                 ],
87 87
             ],
88 88
         ],
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
             'class' => IntegerType::class,
93 93
             'default_options' => [
94 94
                 'constraints' => [
95
-                    'not_blank' => [],
95
+                    'not_blank' => [ ],
96 96
                     'type' => [
97 97
                         'type' => 'integer',
98 98
                     ],
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
             'class' => MoneyType::class,
104 104
             'default_options' => [
105 105
                 'constraints' => [
106
-                    'not_blank' => [],
106
+                    'not_blank' => [ ],
107 107
                     'type' => [
108 108
                         'type' => 'numeric',
109 109
                     ],
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             'class' => NumberType::class,
115 115
             'default_options' => [
116 116
                 'constraints' => [
117
-                    'not_blank' => [],
117
+                    'not_blank' => [ ],
118 118
                     'type' => [
119 119
                         'type' => 'numeric',
120 120
                     ],
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
             'class' => PercentType::class,
126 126
             'default_options' => [
127 127
                 'constraints' => [
128
-                    'not_blank' => [],
128
+                    'not_blank' => [ ],
129 129
                     'type' => [
130 130
                         'type' => 'numeric',
131 131
                     ],
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
             'class' => ChoiceType::class,
139 139
             'default_options' => [
140 140
                 'constraints' => [
141
-                    'not_blank' => [],
141
+                    'not_blank' => [ ],
142 142
                 ],
143 143
             ],
144 144
         ],
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
             'class' => CountryType::class,
147 147
             'default_options' => [
148 148
                 'constraints' => [
149
-                    'not_blank' => [],
149
+                    'not_blank' => [ ],
150 150
                 ],
151 151
             ],
152 152
         ],
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
             'class' => LanguageType::class,
155 155
             'default_options' => [
156 156
                 'constraints' => [
157
-                    'not_blank' => [],
157
+                    'not_blank' => [ ],
158 158
                 ],
159 159
             ],
160 160
         ],
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
             'class' => LocaleType::class,
163 163
             'default_options' => [
164 164
                 'constraints' => [
165
-                    'not_blank' => [],
165
+                    'not_blank' => [ ],
166 166
                 ],
167 167
             ],
168 168
         ],
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
             'class' => TimezoneType::class,
171 171
             'default_options' => [
172 172
                 'constraints' => [
173
-                    'not_blank' => [],
173
+                    'not_blank' => [ ],
174 174
                 ],
175 175
             ],
176 176
         ],
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
             'class' => CurrencyType::class,
179 179
             'default_options' => [
180 180
                 'constraints' => [
181
-                    'not_blank' => [],
181
+                    'not_blank' => [ ],
182 182
                 ],
183 183
             ],
184 184
         ],
@@ -194,8 +194,8 @@  discard block
 block discarded – undo
194 194
 //                    'placeholder' => 'dd/mm/aaaa',
195 195
 //                ]
196 196
                 'constraints' => [
197
-                    'not_blank' => [],
198
-                    'date' => [],
197
+                    'not_blank' => [ ],
198
+                    'date' => [ ],
199 199
                 ],
200 200
             ],
201 201
         ],
@@ -206,8 +206,8 @@  discard block
 block discarded – undo
206 206
                 'widget' => 'single_text',
207 207
                 'with_seconds' => false,
208 208
                 'constraints' => [
209
-                    'not_blank' => [],
210
-                    'time' => [],
209
+                    'not_blank' => [ ],
210
+                    'time' => [ ],
211 211
                 ],
212 212
             ],
213 213
         ],
@@ -245,10 +245,10 @@  discard block
 block discarded – undo
245 245
 
246 246
     public static function getDefaultTypeConfig(string $inputType): array
247 247
     {
248
-        if (!isset(self::SUPPORTED_TYPES[$inputType])) {
248
+        if (!isset(self::SUPPORTED_TYPES[ $inputType ])) {
249 249
             throw new NotSupportedFormTypeException($inputType);
250 250
         }
251 251
 
252
-        return self::SUPPORTED_TYPES[$inputType];
252
+        return self::SUPPORTED_TYPES[ $inputType ];
253 253
     }
254 254
 }
Please login to merge, or discard this patch.