@@ -321,7 +321,9 @@ protected function reloadTree()
321321 $ value = $ input ->hasValue ('value ' ) ? $ input ->getValue ('value ' , true ) : '' ;
322322
323323 $ fieldName = $ this ->getFieldName ();
324- assert (is_string ($ fieldName ));
324+ if (null === $ fieldName ) {
325+ throw new ResponseException (new Response ('No update of the widget, as no field name was found. ' ));
326+ }
325327
326328 $ widget = $ this ->getWidget ($ fieldName , $ serializedId , $ value );
327329 assert ($ widget instanceof Widget);
@@ -381,6 +383,9 @@ protected function setLegendState()
381383 * Get the field name.
382384 *
383385 * @return null|string
386+ *
387+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
388+ * @SuppressWarnings(PHPMD.NPathComplexity)
384389 */
385390 private function getFieldName ()
386391 {
@@ -392,7 +397,7 @@ private function getFieldName()
392397
393398 $ fieldName = $ inputProvider ->hasValue ('name ' ) ? $ inputProvider ->getValue ('name ' ) : null ;
394399 if (null === $ fieldName ) {
395- return $ fieldName ;
400+ return null ;
396401 }
397402
398403 if (('select ' !== $ inputProvider ->getParameter ('act ' )) && ('edit ' !== $ inputProvider ->getParameter ('mode ' ))) {
@@ -405,16 +410,19 @@ private function getFieldName()
405410 $ sessionStorage = $ environment ->getSessionStorage ();
406411 assert ($ sessionStorage instanceof SessionStorageInterface);
407412
408- /** @var array{models: list<string>} $session */
409413 $ session = $ sessionStorage ->get ($ dataDefinition ->getName () . '. ' . $ inputProvider ->getParameter ('select ' ));
414+ if (!is_array ($ session ) || !isset ($ session ['models ' ])) {
415+ return null ;
416+ }
417+ /** @var array{models: list<string>} $session */
410418
411419 $ originalPropertyName = null ;
412420 foreach ($ session ['models ' ] as $ modelId ) {
413421 if (null !== $ originalPropertyName ) {
414422 break ;
415423 }
416424
417- $ propertyNamePrefix = str_replace (':: ' , '____ ' , $ modelId ) . '_ ' ;
425+ $ propertyNamePrefix = str_replace (':: ' , '____ ' , (( string ) $ modelId) ) . '_ ' ;
418426 if (!str_starts_with ($ fieldName , $ propertyNamePrefix )) {
419427 continue ;
420428 }
0 commit comments