1- <?php declare (strict_types=1 );
1+ <?php
2+
3+ declare (strict_types=1 );
24
35namespace Kiboko \Plugin \FastMap ;
46
7+ use function Kiboko \Component \SatelliteToolbox \Configuration \mutuallyDependentFields ;
8+ use function Kiboko \Component \SatelliteToolbox \Configuration \mutuallyExclusiveFields ;
59use Kiboko \Contract \Configurator \PluginConfigurationInterface ;
610use Symfony \Component \Config \Definition \Builder \TreeBuilder ;
711use Symfony \Component \Config \Definition \NodeInterface ;
812use Symfony \Component \ExpressionLanguage \Expression ;
9- use function Kiboko \Component \SatelliteToolbox \Configuration \mutuallyExclusiveFields ;
10- use function Kiboko \Component \SatelliteToolbox \Configuration \mutuallyDependentFields ;
1113
1214final class Configuration implements PluginConfigurationInterface
1315{
1416 public function __construct (
1517 private string $ name = 'fastmap '
1618 ) {}
1719
18- public function getConfigTreeBuilder ()
20+ public function getConfigTreeBuilder (): TreeBuilder
1921 {
2022 $ builder = new TreeBuilder ($ this ->name );
2123
24+ /* @phpstan-ignore-next-line */
2225 $ builder ->getRootNode ()
2326 ->validate ()
2427 ->always ($ this ->cleanupFields ('conditional ' , 'expression_language ' , 'map ' , 'list ' , 'object ' , 'collection ' ))
@@ -39,9 +42,7 @@ public function getConfigTreeBuilder()
3942 ->append ($ this ->getCollectionTreeBuilder ()->getRootNode ())
4043 ->end ()
4144 ->validate ()
42- ->ifTrue (function ($ value ) {
43- return !is_array ($ value );
44- })
45+ ->ifTrue (fn ($ value ) => !\is_array ($ value ))
4546 ->thenInvalid ('Your configuration should be an array. ' )
4647 ->end ()
4748 ->validate ()
@@ -81,8 +82,7 @@ public function getConfigTreeBuilder()
8182
8283 private function evaluateMap ($ children )
8384 {
84- $ node = $ this ->getMapNode ();
85- return $ node ->finalize ($ children );
85+ return $ this ->getMapNode ()->finalize ($ children );
8686 }
8787
8888 private function evaluateList ($ children )
@@ -124,11 +124,11 @@ private function cleanupFields(string ...$fieldNames): \Closure
124124 {
125125 return function (array $ value ) use ($ fieldNames ) {
126126 foreach ($ fieldNames as $ fieldName ) {
127- if (!array_key_exists ($ fieldName , $ value )) {
127+ if (!\ array_key_exists ($ fieldName , $ value )) {
128128 continue ;
129129 }
130130
131- if (!is_array ($ value [$ fieldName ]) || count ($ value [$ fieldName ]) <= 0 ) {
131+ if (!\ is_array ($ value [$ fieldName ]) || \ count ($ value [$ fieldName ]) <= 0 ) {
132132 unset($ value [$ fieldName ]);
133133 }
134134 }
@@ -141,6 +141,7 @@ private function getChildTreeBuilder(string $name): TreeBuilder
141141 {
142142 $ builder = new TreeBuilder ($ name );
143143
144+ /* @phpstan-ignore-next-line */
144145 $ builder ->getRootNode ()
145146 ->arrayPrototype ()
146147 ->validate ()
@@ -202,59 +203,43 @@ private function getChildTreeBuilder(string $name): TreeBuilder
202203 ->scalarNode ('constant ' )->end ()
203204 ->variableNode ('map ' )
204205 ->validate ()
205- ->ifTrue (function ($ element ) {
206- return !is_array ($ element );
207- })
206+ ->ifTrue (fn ($ element ) => !\is_array ($ element ))
208207 ->thenInvalid ('The children element must be an array. ' )
209208 ->end ()
210209 ->validate ()
211210 ->ifArray ()
212- ->then (function (array $ children ) {
213- return $ this ->evaluateMap ($ children );
214- })
211+ ->then (fn (array $ children ) => $ this ->evaluateMap ($ children ))
215212 ->end ()
216213 ->end ()
217214 ->variableNode ('list ' )
218215 ->validate ()
219- ->ifTrue (function ($ element ) {
220- return !is_array ($ element );
221- })
216+ ->ifTrue (fn ($ element ) => !\is_array ($ element ))
222217 ->thenInvalid ('The children element must be an array. ' )
223218 ->end ()
224219 ->validate ()
225220 ->ifArray ()
226- ->then (function (array $ children ) {
227- return $ this ->evaluateList ($ children );
228- })
221+ ->then (fn (array $ children ) => $ this ->evaluateList ($ children ))
229222 ->end ()
230223 ->end ()
231224 ->scalarNode ('class ' )->end ()
232225 ->variableNode ('object ' )
233226 ->validate ()
234- ->ifTrue (function ($ element ) {
235- return !is_array ($ element );
236- })
227+ ->ifTrue (fn ($ element ) => !\is_array ($ element ))
237228 ->thenInvalid ('The children element must be an array. ' )
238229 ->end ()
239230 ->validate ()
240231 ->ifArray ()
241- ->then (function (array $ children ) {
242- return $ this ->evaluateObject ($ children );
243- })
232+ ->then (fn (array $ children ) => $ this ->evaluateObject ($ children ))
244233 ->end ()
245234 ->end ()
246235 ->variableNode ('collection ' )
247236 ->validate ()
248- ->ifTrue (function ($ element ) {
249- return !is_array ($ element );
250- })
237+ ->ifTrue (fn ($ element ) => !\is_array ($ element ))
251238 ->thenInvalid ('The children element must be an array. ' )
252239 ->end ()
253240 ->validate ()
254241 ->ifArray ()
255- ->then (function (array $ children ) {
256- return $ this ->evaluateCollection ($ children );
257- })
242+ ->then (fn (array $ children ) => $ this ->evaluateCollection ($ children ))
258243 ->end ()
259244 ->end ()
260245 ->end ()
@@ -268,6 +253,7 @@ public function getConditionalTreeBuilder(): TreeBuilder
268253 {
269254 $ builder = new TreeBuilder ('conditional ' );
270255
256+ /* @phpstan-ignore-next-line */
271257 $ builder ->getRootNode ()
272258 ->arrayPrototype ()
273259 ->validate ()
@@ -284,7 +270,8 @@ public function getConditionalTreeBuilder(): TreeBuilder
284270 ->append ($ this ->getObjectTreeBuilder ()->getRootNode ())
285271 ->append ($ this ->getCollectionTreeBuilder ()->getRootNode ())
286272 ->end ()
287- ->end ();
273+ ->end ()
274+ ;
288275
289276 return $ builder ;
290277 }
0 commit comments