为了账号安全,请及时绑定邮箱和手机立即绑定

Symfony Insight:如何防止 CustomIdGenerator

Symfony Insight:如何防止 CustomIdGenerator

PHP
烙印99 2021-06-23 17:42:28
我在 gitlab-ci 中使用 SymfonyInsight 来提高我的应用程序的代码质量。在这个应用程序中,我需要为我的实体使用 CustomIdGenerator。在我的分析中,我收到一个警告错误:Doctrine Entity Manager 不应作为参数传递。为 CustomIdGenerator 使用的名为“generate”的方法检测到此错误。<?phpnamespace 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;    }}我的实体:<?phpuse 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 仅在这种情况下触发此错误?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 177 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信