src/EventSubscriber/RenewalFormSubscriber.php line 71
<?phpnamespace App\EventSubscriber;use App\Entity\RenewalFormReview;use App\Event\AppEvents;use App\Event\FormEvent;use App\Event\InvoiceEvent;use App\Helper\PropertyHelper;use App\ValueObject\ReviewStatuses;use DateTime;use Doctrine\ORM\EntityManagerInterface;use App\Entity\Invoice;use App\ValueObject\InvoiceTypes;use App\ValueObject\MunicipalityFeePeriods;use Symfony\Component\EventDispatcher\EventDispatcherInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;/*** Class RenewalFormListener*/class RenewalFormSubscriber implements EventSubscriberInterface{/*** @var EntityManagerInterface*/private $entityManager;/*** @var PropertyHelper*/private $propertyHelper;/*** @var EventDispatcherInterface*/private $eventDispatcher;/*** RenewalFormListener constructor.** @param EntityManagerInterface $entityManager* @param PropertyHelper $propertyHelper* @param EventDispatcherInterface $eventDispatcher*/public function __construct(EntityManagerInterface $entityManager,PropertyHelper $propertyHelper,EventDispatcherInterface $eventDispatcher){$this->entityManager = $entityManager;$this->propertyHelper = $propertyHelper;$this->eventDispatcher = $eventDispatcher;}/*** {@inheritdoc}*/public static function getSubscribedEvents(): array{return [AppEvents::RENEWAL_FORM_CREATED => ['onRenewalFormCreated'],];}/*** @param FormEvent $event* @throws \Exception*/public function onRenewalFormCreated(FormEvent $event): void{$property = $event->getForm()->getProperty();$property->setRenewalDate(new DateTime(PropertyHelper::DELAY_FOR_INVOICE));$event->getForm()->setStatus(ReviewStatuses::APPROVED);$nextRenewalDate = $this->propertyHelper->getNextRenewalDate($property);$property->setNextRenewalDate($nextRenewalDate);$this->entityManager->flush();}}