1
- <?php declare (strict_types=1 );
1
+ <?php
2
+
3
+ declare (strict_types=1 );
2
4
3
5
namespace Kiboko \Plugin \FastMap ;
4
6
7
+ use function Kiboko \Component \SatelliteToolbox \Configuration \mutuallyDependentFields ;
8
+ use function Kiboko \Component \SatelliteToolbox \Configuration \mutuallyExclusiveFields ;
5
9
use Kiboko \Contract \Configurator \PluginConfigurationInterface ;
6
10
use Symfony \Component \Config \Definition \Builder \TreeBuilder ;
7
11
use Symfony \Component \Config \Definition \NodeInterface ;
8
12
use Symfony \Component \ExpressionLanguage \Expression ;
9
- use function Kiboko \Component \SatelliteToolbox \Configuration \mutuallyExclusiveFields ;
10
- use function Kiboko \Component \SatelliteToolbox \Configuration \mutuallyDependentFields ;
11
13
12
14
final class Configuration implements PluginConfigurationInterface
13
15
{
14
16
public function __construct (
15
17
private string $ name = 'fastmap '
16
18
) {}
17
19
18
- public function getConfigTreeBuilder ()
20
+ public function getConfigTreeBuilder (): TreeBuilder
19
21
{
20
22
$ builder = new TreeBuilder ($ this ->name );
21
23
24
+ /* @phpstan-ignore-next-line */
22
25
$ builder ->getRootNode ()
23
26
->validate ()
24
27
->always ($ this ->cleanupFields ('conditional ' , 'expression_language ' , 'map ' , 'list ' , 'object ' , 'collection ' ))
@@ -39,9 +42,7 @@ public function getConfigTreeBuilder()
39
42
->append ($ this ->getCollectionTreeBuilder ()->getRootNode ())
40
43
->end ()
41
44
->validate ()
42
- ->ifTrue (function ($ value ) {
43
- return !is_array ($ value );
44
- })
45
+ ->ifTrue (fn ($ value ) => !\is_array ($ value ))
45
46
->thenInvalid ('Your configuration should be an array. ' )
46
47
->end ()
47
48
->validate ()
@@ -81,8 +82,7 @@ public function getConfigTreeBuilder()
81
82
82
83
private function evaluateMap ($ children )
83
84
{
84
- $ node = $ this ->getMapNode ();
85
- return $ node ->finalize ($ children );
85
+ return $ this ->getMapNode ()->finalize ($ children );
86
86
}
87
87
88
88
private function evaluateList ($ children )
@@ -124,11 +124,11 @@ private function cleanupFields(string ...$fieldNames): \Closure
124
124
{
125
125
return function (array $ value ) use ($ fieldNames ) {
126
126
foreach ($ fieldNames as $ fieldName ) {
127
- if (!array_key_exists ($ fieldName , $ value )) {
127
+ if (!\ array_key_exists ($ fieldName , $ value )) {
128
128
continue ;
129
129
}
130
130
131
- if (!is_array ($ value [$ fieldName ]) || count ($ value [$ fieldName ]) <= 0 ) {
131
+ if (!\ is_array ($ value [$ fieldName ]) || \ count ($ value [$ fieldName ]) <= 0 ) {
132
132
unset($ value [$ fieldName ]);
133
133
}
134
134
}
@@ -141,6 +141,7 @@ private function getChildTreeBuilder(string $name): TreeBuilder
141
141
{
142
142
$ builder = new TreeBuilder ($ name );
143
143
144
+ /* @phpstan-ignore-next-line */
144
145
$ builder ->getRootNode ()
145
146
->arrayPrototype ()
146
147
->validate ()
@@ -202,59 +203,43 @@ private function getChildTreeBuilder(string $name): TreeBuilder
202
203
->scalarNode ('constant ' )->end ()
203
204
->variableNode ('map ' )
204
205
->validate ()
205
- ->ifTrue (function ($ element ) {
206
- return !is_array ($ element );
207
- })
206
+ ->ifTrue (fn ($ element ) => !\is_array ($ element ))
208
207
->thenInvalid ('The children element must be an array. ' )
209
208
->end ()
210
209
->validate ()
211
210
->ifArray ()
212
- ->then (function (array $ children ) {
213
- return $ this ->evaluateMap ($ children );
214
- })
211
+ ->then (fn (array $ children ) => $ this ->evaluateMap ($ children ))
215
212
->end ()
216
213
->end ()
217
214
->variableNode ('list ' )
218
215
->validate ()
219
- ->ifTrue (function ($ element ) {
220
- return !is_array ($ element );
221
- })
216
+ ->ifTrue (fn ($ element ) => !\is_array ($ element ))
222
217
->thenInvalid ('The children element must be an array. ' )
223
218
->end ()
224
219
->validate ()
225
220
->ifArray ()
226
- ->then (function (array $ children ) {
227
- return $ this ->evaluateList ($ children );
228
- })
221
+ ->then (fn (array $ children ) => $ this ->evaluateList ($ children ))
229
222
->end ()
230
223
->end ()
231
224
->scalarNode ('class ' )->end ()
232
225
->variableNode ('object ' )
233
226
->validate ()
234
- ->ifTrue (function ($ element ) {
235
- return !is_array ($ element );
236
- })
227
+ ->ifTrue (fn ($ element ) => !\is_array ($ element ))
237
228
->thenInvalid ('The children element must be an array. ' )
238
229
->end ()
239
230
->validate ()
240
231
->ifArray ()
241
- ->then (function (array $ children ) {
242
- return $ this ->evaluateObject ($ children );
243
- })
232
+ ->then (fn (array $ children ) => $ this ->evaluateObject ($ children ))
244
233
->end ()
245
234
->end ()
246
235
->variableNode ('collection ' )
247
236
->validate ()
248
- ->ifTrue (function ($ element ) {
249
- return !is_array ($ element );
250
- })
237
+ ->ifTrue (fn ($ element ) => !\is_array ($ element ))
251
238
->thenInvalid ('The children element must be an array. ' )
252
239
->end ()
253
240
->validate ()
254
241
->ifArray ()
255
- ->then (function (array $ children ) {
256
- return $ this ->evaluateCollection ($ children );
257
- })
242
+ ->then (fn (array $ children ) => $ this ->evaluateCollection ($ children ))
258
243
->end ()
259
244
->end ()
260
245
->end ()
@@ -268,6 +253,7 @@ public function getConditionalTreeBuilder(): TreeBuilder
268
253
{
269
254
$ builder = new TreeBuilder ('conditional ' );
270
255
256
+ /* @phpstan-ignore-next-line */
271
257
$ builder ->getRootNode ()
272
258
->arrayPrototype ()
273
259
->validate ()
@@ -284,7 +270,8 @@ public function getConditionalTreeBuilder(): TreeBuilder
284
270
->append ($ this ->getObjectTreeBuilder ()->getRootNode ())
285
271
->append ($ this ->getCollectionTreeBuilder ()->getRootNode ())
286
272
->end ()
287
- ->end ();
273
+ ->end ()
274
+ ;
288
275
289
276
return $ builder ;
290
277
}
0 commit comments