Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| IdGeneratorRetoure | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
3.01 | |
0.00% |
0 / 1 |
| generateId | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
3.01 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Satag\AmicronEntityBundle\Doctrine; |
| 6 | |
| 7 | use Doctrine\DBAL\Exception; |
| 8 | use Doctrine\ORM\EntityManagerInterface; |
| 9 | use Doctrine\ORM\Id\AbstractIdGenerator; |
| 10 | use Satag\AmicronEntityBundle\Entity\Retoure; |
| 11 | |
| 12 | class 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 | } |