<commit_before><?php

namespace AppBundle\EventListener;

use AppBundle\Entity as EntityDir;
use Doctrine\ORM\Event\LifecycleEventArgs;

class DoctrineListener
{
    public function prePersist(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();
        $entityManager = $args->getEntityManager();

        if ($entity instanceof EntityDir\Report\Report && !$entity->getId()) {
            $reportRepo = $entityManager->getRepository('AppBundle\Entity\Report\Report'); /* @var $reportRepo EntityDir\Report\ReportRepository */
            $reportRepo->addDebtsToReportIfMissing($entity);
            $reportRepo->addMoneyShortCategoriesIfMissing($entity);
        }

        if ($entity instanceof EntityDir\Odr\Odr && !$entity->getId()) {
            $odrRepo = $entityManager->getRepository('AppBundle\Entity\Odr\Odr');
            /* @var $odrRepo EntityDir\Odr\OdrRepository */
            $odrRepo->addDebtsToOdrIfMissing($entity);
            $odrRepo->addIncomeBenefitsToOdrIfMissing($entity);
        }

        if ($entity instanceof EntityDir\Report\MoneyTransactionShortIn && !$entity->getId()) {
            $entity->getReport()->setMoneyTransactionsShortInExist('yes');
        }

        if ($entity instanceof EntityDir\Report\MoneyTransactionShortOut && !$entity->getId()) {
            $entity->getReport()->setMoneyTransactionsShortOutExist('yes');
        }
    }

    public function preRemove(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();

        if ($entity instanceof EntityDir\Report\MoneyTransactionShortIn) {
            $report = $entity->getReport();
            if (count($report->getMoneyTransactionsShortIn()) === 1) {
                $report->setMoneyTransactionsShortInExist('no');
            }
        }

        if ($entity instanceof EntityDir\Report\MoneyTransactionShortOut) {
            $report = $entity->getReport();
            if (count($report->getMoneyTransactionsShortOut()) === 1) {
                $report->setMoneyTransactionsShortOutExist('no');
            }
        }

        if ($entity instanceof EntityDir\Report\Contact) {
            $report = $entity->getReport();
            if (count($report->getContacts()) === 1) {
                $report->setReasonForNoContacts(null);
            }
        }

        if ($entity instanceof EntityDir\Report\Gift) {
            $report = $entity->getReport();
            if (count($report->getGifts()) === 1) {
                $report->setGiftsExist(null);
            }
        }

        if ($entity instanceof EntityDir\Report\Decision) {
            $report = $entity->getReport();
            if (count($report->getDecisions()) === 1) {
                $report->setReasonForNoDecisions(null);
            }
        }

        if ($entity instanceof EntityDir\Report\Expense) {
            $report = $entity->getReport();
            if (count($report->getExpenses()) === 1) {
                $report->setPaidForAnything(null);
            }
        }

        if ($entity instanceof EntityDir\Report\MoneyTransfer) {
            $report = $entity->getReport();
            if (count($report->getMoneyTransfers()) === 1) {
                $report->setNoTransfersToAdd(null);
            }
        }


    }
}<commit_msg>DDPB-918-delete-last-record-logic bank accounts<commit_after><?php

namespace AppBundle\EventListener;

use AppBundle\Entity as EntityDir;
use Doctrine\ORM\Event\LifecycleEventArgs;

class DoctrineListener
{
    public function prePersist(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();
        $entityManager = $args->getEntityManager();

        if ($entity instanceof EntityDir\Report\Report && !$entity->getId()) {
            $reportRepo = $entityManager->getRepository('AppBundle\Entity\Report\Report'); /* @var $reportRepo EntityDir\Report\ReportRepository */
            $reportRepo->addDebtsToReportIfMissing($entity);
            $reportRepo->addMoneyShortCategoriesIfMissing($entity);
        }

        if ($entity instanceof EntityDir\Odr\Odr && !$entity->getId()) {
            $odrRepo = $entityManager->getRepository('AppBundle\Entity\Odr\Odr');
            /* @var $odrRepo EntityDir\Odr\OdrRepository */
            $odrRepo->addDebtsToOdrIfMissing($entity);
            $odrRepo->addIncomeBenefitsToOdrIfMissing($entity);
        }

        if ($entity instanceof EntityDir\Report\MoneyTransactionShortIn && !$entity->getId()) {
            $entity->getReport()->setMoneyTransactionsShortInExist('yes');
        }

        if ($entity instanceof EntityDir\Report\MoneyTransactionShortOut && !$entity->getId()) {
            $entity->getReport()->setMoneyTransactionsShortOutExist('yes');
        }
    }

    public function preRemove(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();

        if ($entity instanceof EntityDir\Report\MoneyTransactionShortIn) {
            $report = $entity->getReport();
            if (count($report->getMoneyTransactionsShortIn()) === 1) {
                $report->setMoneyTransactionsShortInExist('no');
            }
        }

        if ($entity instanceof EntityDir\Report\MoneyTransactionShortOut) {
            $report = $entity->getReport();
            if (count($report->getMoneyTransactionsShortOut()) === 1) {
                $report->setMoneyTransactionsShortOutExist('no');
            }
        }

        if ($entity instanceof EntityDir\Report\Contact) {
            $report = $entity->getReport();
            if (count($report->getContacts()) === 1) {
                $report->setReasonForNoContacts(null);
            }
        }

        if ($entity instanceof EntityDir\Report\Gift) {
            $report = $entity->getReport();
            if (count($report->getGifts()) === 1) {
                $report->setGiftsExist(null);
            }
        }

        if ($entity instanceof EntityDir\Report\Decision) {
            $report = $entity->getReport();
            if (count($report->getDecisions()) === 1) {
                $report->setReasonForNoDecisions(null);
            }
        }

        if ($entity instanceof EntityDir\Report\Expense) {
            $report = $entity->getReport();
            if (count($report->getExpenses()) === 1) {
                $report->setPaidForAnything(null);
            }
        }

        if ($entity instanceof EntityDir\Report\MoneyTransfer) {
            $report = $entity->getReport();
            if (count($report->getMoneyTransfers()) === 1) {
                $report->setNoTransfersToAdd(null);
            }
        }

    }
}
{'fraction_non_alphanumeric': 0.13841936957514847, 'fraction_numerical': 0.0025887010811633925, 'mean_word_length': 2.3021618903971843, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2644285', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1758, 'n_words': 264}