Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHPStan don';我看不到合适的ObjectManager的条令_Php_Symfony_Doctrine Orm_Doctrine_Phpstan - Fatal编程技术网

PHPStan don';我看不到合适的ObjectManager的条令

PHPStan don';我看不到合适的ObjectManager的条令,php,symfony,doctrine-orm,doctrine,phpstan,Php,Symfony,Doctrine Orm,Doctrine,Phpstan,我尝试用PHPStan改进代码。 我已经安装了: 这是我的phpstan.neon: includes: - vendor/phpstan/phpstan/conf/config.levelmax.neon - vendor/phpstan/phpstan-symfony/extension.neon - vendor/phpstan/phpstan-doctrine/extension.neon - vendor/phpstan/phpstan-doctrine/r

我尝试用PHPStan改进代码。 我已经安装了:

这是我的phpstan.neon:

includes:
  - vendor/phpstan/phpstan/conf/config.levelmax.neon
  - vendor/phpstan/phpstan-symfony/extension.neon
  - vendor/phpstan/phpstan-doctrine/extension.neon
  - vendor/phpstan/phpstan-doctrine/rules.neon
  - vendor/phpstan/phpstan-phpunit/extension.neon
  - vendor/phpstan/phpstan-phpunit/rules.neon
parameters:
  paths:
    - %currentWorkingDirectory%/src
    - %currentWorkingDirectory%/tests
  symfony:
    container_xml_path: '%currentWorkingDirectory%/var/cache/dev/srcApp_KernelDevDebugContainer.xml'
  autoload_directories:
    - %currentWorkingDirectory%/tests
我还测试了调用下一个函数:

$kernel = static::bootKernel();
$doctrine = $kernel->getContainer()->get('doctrine');
$doctrine->getManager()->getConfiguration();
$doctrine->getManager()->getEventManager();
PHPStan抱怨说:

Call to an undefined method Doctrine\Common\Persistence\ObjectManager::getConfiguration().
Call to an undefined method Doctrine\Common\Persistence\ObjectManager::getEventManager().
我研究了
$doctrine->getManager()
我有
doctrine\ORM\EntityManagerInterface
扩展
doctrine\Common\Persistence\ObjectManager
,但PHPStan认为我有
doctrine\Common\Persistence\ObjectManager

如何告诉PHPStan,
$doctrine->getManager()
doctrine\ORM\EntityManagerInterface

您可以:

  • 添加一个内联PHPDoc(在任何地方工作):
  • /**@var\Doctrine\ORM\entitymanager接口*/
    $doctrine=$kernel->getContainer()->get('doctrine');
    
  • 使用断言(仅在测试中有效):
  • $doctrine=$kernel->getContainer()->get('doctrine');
    self::assertInstanceOf(EntityManagerInterface::class$原则);
    
    您可以:

  • 添加一个内联PHPDoc(在任何地方工作):
  • /**@var\Doctrine\ORM\entitymanager接口*/
    $doctrine=$kernel->getContainer()->get('doctrine');
    
  • 使用断言(仅在测试中有效):
  • $doctrine=$kernel->getContainer()->get('doctrine');
    self::assertInstanceOf(EntityManagerInterface::class$原则);