PhpStorm配置PHPStan与Docker一起用于Symfony

huangapple go评论144阅读模式
英文:

PhpStorm configuration of PHPstan for Symfony with Docker

问题

我正在尝试在使用 这个模板 的 docker 化 Symfony 项目中使 PHPstan 工作。该项目使用 PHP 8.1.16,一切正常。

现在,我想充分利用我的 docker 容器中安装的 PHP CLI,而不是本地的 PHP CLI。

我按照这个教程 配置了 PhpStorm 使用我的 docker 容器中安装的 PHP CLI,然后配置了 PHPstan 和 PHP CS Fixer 来使用这个 CLI。

一切都被正确检测到,但是 PHPstan 无法使用 phpstan.neon 中提供的 container_xml_path 的路径。

这是我的 phpstan.neon 文件:

includes:
    - vendor/phpstan/phpstan-doctrine/extension.neon
    - vendor/phpstan/phpstan-doctrine/rules.neon
    - vendor/phpstan/phpstan-symfony/extension.neon
    - vendor/phpstan/phpstan-symfony/rules.neon
    - vendor/phpstan/phpstan-phpunit/extension.neon
    - vendor/phpstan/phpstan-phpunit/rules.neon
    - vendor/phpstan/phpstan-strict-rules/rules.neon
    - vendor/phpstan/phpstan-deprecation-rules/rules.neon

parameters:
    symfony:
        container_xml_path: var/cache/dev/App_KernelDevDebugContainer.xml
        console_application_loader: bin/console
        consoleApplicationLoader: tests/console-application.php
    level: 9
    paths:
        - src
        - tests

这是 PHPstan 自动运行时出现的错误:

PhpStorm配置PHPStan与Docker一起用于Symfony

文件路径没问题,但文件只存在于容器中,我的本地 var 目录是空的。

这是问题吗,还是我漏掉了什么?如何正确链接它?

英文:

I am trying to make PHPstan work for a dockerized Symfony project using this template. The project use PHP 8.1.16. Works fine.

Now I want to push it a little bit to fully use the PHP CLI installed in my docker container instead of the local one.

I followed this tutorial to make PhpStorm use the PHP CLI installed in my docker container. Then configured PHPstan and PHP CS Fixer to use this CLI.

Everything is detected fine but PHPstan can't make use of the path provided for container_xml_path in phpstan.neon.

Here is my phpstan.neon:

includes:
    - vendor/phpstan/phpstan-doctrine/extension.neon
    - vendor/phpstan/phpstan-doctrine/rules.neon
    - vendor/phpstan/phpstan-symfony/extension.neon
    - vendor/phpstan/phpstan-symfony/rules.neon
    - vendor/phpstan/phpstan-phpunit/extension.neon
    - vendor/phpstan/phpstan-phpunit/rules.neon
    - vendor/phpstan/phpstan-strict-rules/rules.neon
    - vendor/phpstan/phpstan-deprecation-rules/rules.neon

parameters:
    symfony:
        container_xml_path: var/cache/dev/App_KernelDevDebugContainer.xml
        console_application_loader: bin/console
        consoleApplicationLoader: tests/console-application.php
    level: 9
    paths:
        - src
        - tests

And this is the error I get when PHPstan automatically run :

PhpStorm配置PHPStan与Docker一起用于Symfony

The file path is okay, but the file only exist in the container, my local var dir is empty.

Is that the problem or am I missing the point? And how can I link it properly?

答案1

得分: 1

I got it.
What was missing is the "Connect to existing container ('docker-compose exec')." step described here.
I wasn't able to see it because I chose "Docker" over "Docker compose" in the dialog box step 5 of this tutorial.

Also, if someone struggles with a similar problem, make sure you use the correct Docker version (docker-compose or the latest docker compose).

To use the new docker compose, check the box "Use Compose V2 (beta)" under Settings Build, Execution, Deployment > Docker > Tools.

英文:

I got it.
What was missing is the "Connect to existing container ('docker-compose exec') ." step described here
I wasn't able to see it because i choose "Docker" over "Docker compose" in the dialog box step 5 of this tutorial.

Also, if someone struggle with a similar problem, make sure you use correct docker version (docker-compose or the latest docker compose).

To use the new docker compose, check the box "Use Compose V2 (beta)" under Settings Build, Execution, Deployment > Docker > Tools.

huangapple
  • 本文由 发表于 2023年3月7日 19:33:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75661440.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定