I use SymfonyInsight in a gitlab-ci to improve the code quality of my application. In this app, I need to use a CustomIdGenerator for my entities.
In my analysis, I got a warning error : The Doctrine Entity Manager should not be passed as an argument. This error is detected for the method called "generate" used by the CustomIdGenerator.
<?php
namespace MyApp\Generator;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Id\AbstractIdGenerator;
class IDGenerator extends AbstractIdGenerator
{
/**
* Generates an identifier for an entity.
*
* @param EntityManager $em
* @param object|null $entity
* @return int
* @throws \Doctrine\Common\Persistence\Mapping\MappingException
* @throws \ReflectionException
*/
public function generate(EntityManager $em, $entity)
{
$class = $em->getMetadataFactory()->getMetadataFor(get_class($entity))->getName();
$res = <My own logic>
return $res;
}
}
My Entity :
<?php
use Doctrine\ORM\Mapping as ORM;
/**
*
* @ORM\Table(name="my_table")
* @ORM\Entity
*/
class Entity
{
/**
* @var integer
*
* @ORM\Column(name="id_unique", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="IDGenerator")
*/
private $id;
Is there a way to prevent SymfonyInsight to trigger this error only in this case ?