我在 gitlab-ci 中使用 SymfonyInsight 来提高我的应用程序的代码质量。在这个应用程序中,我需要为我的实体使用 CustomIdGenerator。
在我的分析中,我收到一个警告错误:Doctrine Entity Manager 不应作为参数传递。为 CustomIdGenerator 使用的名为“generate”的方法检测到此错误。
<?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;
}
}
我的实体:
<?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;
有没有办法阻止 SymfonyInsight 仅在这种情况下触发此错误?