我在一个项目中使用学说(不是 symfony)。在这个项目中,我还使用了 phpstan,我同时安装了phpstan/phpstan-doctrine
和phpstan/extension-installer
. 我的 phpstan.neon 是这样的:
parameters:
level: 8
paths:
- src/
doctrine:
objectManagerLoader: tests/object-manager.php
在 tests/object-manager.php 中,它返回调用返回实体管理器的函数的结果。
这是创建实体管理器的代码
$database_url = $_ENV['DATABASE_URL'];
$isDevMode = $this->isDevMode();
$proxyDir = null;
$cache = null;
$useSimpleAnnotationReader = false;
$config = Setup::createAnnotationMetadataConfiguration(
[$this->getProjectDirectory() . '/src'],
$isDevMode,
$proxyDir,
$cache,
$useSimpleAnnotationReader
);
// database configuration parameters
$conn = [
'url' => $database_url,
];
// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);
当我运行时,vendor/bin/phpstan analyze
我收到此错误:
Internal error: An exception occurred in the driver: SQLSTATE[08006] [7] could not translate host name "postgres_db" to address: nodename nor servname provided, or not known
这是因为我正在使用 docker,而我的数据库 url 是postgres://user:password@postgres_db/database
postgres_db
我的数据库容器的名称,因此主机名在 docker 容器内是已知的。
当我在容器内运行 phpstan 时,我没有错误。
那么有没有办法在 docker 之外运行 phpstan ?因为我很确定当我推送我的代码时,github 工作流程会因此而失败
phpstan 需要尝试访问数据库吗?