@@ -222,6 +222,7 @@ public function edit(AdminContext $context)
222222 $ this ->container ->get (EntityFactory::class)->processFields ($ context ->getEntity (), FieldCollection::new ($ this ->configureFields (Crud::PAGE_EDIT )));
223223 $ context ->getCrud ()->setFieldAssets ($ this ->getFieldAssets ($ context ->getEntity ()->getFields ()));
224224 $ this ->container ->get (EntityFactory::class)->processActions ($ context ->getEntity (), $ context ->getCrud ()->getActionsConfig ());
225+ /** @var TEntity $entityInstance */
225226 $ entityInstance = $ context ->getEntity ()->getInstance ();
226227
227228 if ($ context ->getRequest ()->isXmlHttpRequest ()) {
@@ -301,14 +302,17 @@ public function new(AdminContext $context)
301302 throw new InsufficientEntityPermissionException ($ context );
302303 }
303304
304- $ context ->getEntity ()->setInstance ($ this ->createEntity ($ context ->getEntity ()->getFqcn ()));
305+ /** @var class-string<TEntity> $entityFqcn */
306+ $ entityFqcn = $ context ->getEntity ()->getFqcn ();
307+ $ context ->getEntity ()->setInstance ($ this ->createEntity ($ entityFqcn ));
305308 $ this ->container ->get (EntityFactory::class)->processFields ($ context ->getEntity (), FieldCollection::new ($ this ->configureFields (Crud::PAGE_NEW )));
306309 $ context ->getCrud ()->setFieldAssets ($ this ->getFieldAssets ($ context ->getEntity ()->getFields ()));
307310 $ this ->container ->get (EntityFactory::class)->processActions ($ context ->getEntity (), $ context ->getCrud ()->getActionsConfig ());
308311
309312 $ newForm = $ this ->createNewForm ($ context ->getEntity (), $ context ->getCrud ()->getNewFormOptions (), $ context );
310313 $ newForm ->handleRequest ($ context ->getRequest ());
311314
315+ /** @var TEntity $entityInstance */
312316 $ entityInstance = $ newForm ->getData ();
313317 $ context ->getEntity ()->setInstance ($ entityInstance );
314318
@@ -359,11 +363,14 @@ public function delete(AdminContext $context)
359363 throw new InsufficientEntityPermissionException ($ context );
360364 }
361365
362- $ csrfToken = $ context ->getRequest ()->request ->get ('token ' );
366+ $ csrfToken = $ context ->getRequest ()->request ->has ('token ' )
367+ ? (string ) $ context ->getRequest ()->request ->get ('token ' )
368+ : null ;
363369 if ($ this ->container ->has ('security.csrf.token_manager ' ) && !$ this ->isCsrfTokenValid ('ea-delete ' , $ csrfToken )) {
364370 return $ this ->redirectToRoute ($ context ->getDashboardRouteName ());
365371 }
366372
373+ /** @var TEntity $entityInstance */
367374 $ entityInstance = $ context ->getEntity ()->getInstance ();
368375
369376 $ event = new BeforeEntityDeletedEvent ($ entityInstance );
@@ -394,6 +401,9 @@ public function delete(AdminContext $context)
394401 return $ this ->redirect ($ this ->container ->get (AdminUrlGenerator::class)->setController ($ context ->getCrud ()->getControllerFqcn ())->setAction (Action::INDEX )->unset (EA ::ENTITY_ID )->generateUrl ());
395402 }
396403
404+ /**
405+ * @param BatchActionDto<TEntity> $batchActionDto
406+ */
397407 public function batchDelete (AdminContext $ context , BatchActionDto $ batchActionDto ): Response
398408 {
399409 $ event = new BeforeCrudActionEvent ($ context );
@@ -406,11 +416,12 @@ public function batchDelete(AdminContext $context, BatchActionDto $batchActionDt
406416 return $ this ->redirectToRoute ($ context ->getDashboardRouteName ());
407417 }
408418
419+ /** @var EntityManagerInterface $entityManager */
409420 $ entityManager = $ this ->container ->get ('doctrine ' )->getManagerForClass ($ batchActionDto ->getEntityFqcn ());
410421 $ repository = $ entityManager ->getRepository ($ batchActionDto ->getEntityFqcn ());
411422 foreach ($ batchActionDto ->getEntityIds () as $ entityId ) {
412423 $ entityInstance = $ repository ->find ($ entityId );
413- if (! $ entityInstance ) {
424+ if (null === $ entityInstance ) {
414425 continue ;
415426 }
416427
@@ -559,6 +570,9 @@ protected function getContext(): ?AdminContext
559570 return $ this ->container ->get (AdminContextProvider::class)->getContext ();
560571 }
561572
573+ /**
574+ * @param EntityDto<TEntity> $entityDto
575+ */
562576 protected function ajaxEdit (EntityDto $ entityDto , ?string $ propertyName , bool $ newValue ): AfterCrudActionEvent
563577 {
564578 $ field = $ entityDto ->getFields ()->getByProperty ($ propertyName );
@@ -568,7 +582,9 @@ protected function ajaxEdit(EntityDto $entityDto, ?string $propertyName, bool $n
568582
569583 $ this ->container ->get (EntityUpdater::class)->updateProperty ($ entityDto , $ propertyName , $ newValue );
570584
571- $ event = new BeforeEntityUpdatedEvent ($ entityDto ->getInstance ());
585+ /** @var TEntity $entityInstance */
586+ $ entityInstance = $ entityDto ->getInstance ();
587+ $ event = new BeforeEntityUpdatedEvent ($ entityInstance );
572588 $ this ->container ->get ('event_dispatcher ' )->dispatch ($ event );
573589 $ entityInstance = $ event ->getEntityInstance ();
574590
0 commit comments