Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
IdGeneratorRetoure
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 1
 generateId
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3declare(strict_types=1);
4
5namespace Satag\AmicronEntityBundle\Doctrine;
6
7use Doctrine\DBAL\Exception;
8use Doctrine\ORM\EntityManagerInterface;
9use Doctrine\ORM\Id\AbstractIdGenerator;
10use Satag\AmicronEntityBundle\Entity\Retoure;
11
12class IdGeneratorRetoure extends AbstractIdGenerator
13{
14    /**
15     * @throws Exception
16     */
17    public function generateId(EntityManagerInterface $em, ?object $entity): mixed
18    {
19        if (!$entity instanceof Retoure) {
20            throw new \LogicException('Entity must be an instance of Retoure');
21        }
22
23        $dbConnection = $em->getConnection();
24
25        if ($entity->getRmanr() === null) {
26            $nextvalQuery = $dbConnection->getDatabasePlatform()->getSequenceNextValSQL('GEN_RMANR');
27            $nextNr = $dbConnection->fetchOne($nextvalQuery);
28            $entity->setRmanr((int) $nextNr);
29        }
30
31        $nextvalQuery = $dbConnection->getDatabasePlatform()->getSequenceNextValSQL('GEN_LFDNR');
32
33        return $dbConnection->fetchOne($nextvalQuery);
34    }
35}