导入被突出显示,就像包不存在一样 (Symfony 4)

Imports are highlighted like the packages do not exist (Symfony 4)

我正在使用 PhpStorm 2018.1 开发 Symfony 4 项目

我经常看到 use 声明突出显示,就好像它们没有与 composer 一起安装一样。

The class belongs to a package which is not directly required in your composer.json. Please add the package into your composer.json.

以下已安装并显示在我的 composer.json 文件中:

我是不是遗漏了什么或者这是 PhpStorm 的问题?

composer.json

{
    "type": "project",
    "license": "proprietary",
    "platform": {
        "php": "7.1"
    },
    "require": {
        "php": "^7.1",
        "ext-iconv": "*",
        "sensio/framework-extra-bundle": "^5.1",
        "stof/doctrine-extensions-bundle": "^1.3",
        "symfony/asset": "^4.1",
        "symfony/console": "^4.1",
        "symfony/expression-language": "^4.1",
        "symfony/flex": "^1.0",
        "symfony/form": "^4.1",
        "symfony/framework-bundle": "^4.1",
        "symfony/lts": "^4@dev",
        "symfony/maker-bundle": "^1.5",
        "symfony/monolog-bundle": "^3.3",
        "symfony/orm-pack": "^1.0",
        "symfony/process": "^4.1",
        "symfony/profiler-pack": "^1.0",
        "symfony/security-bundle": "^4.1",
        "symfony/security-guard": "^4.1",
        "symfony/serializer-pack": "*",
        "symfony/swiftmailer-bundle": "^3.1",
        "symfony/twig-bundle": "^4.1",
        "symfony/validator": "^4.1",
        "symfony/var-dumper": "^4.1",
        "symfony/web-link": "^4.1",
        "symfony/webpack-encore-pack": "^1.0",
        "symfony/yaml": "^4.1"
    },
    "require-dev": {
        "doctrine/doctrine-fixtures-bundle": "^3.0",
        "symfony/debug-pack": "*",
        "symfony/dotenv": "^4.1",
        "symfony/test-pack": "^1.0",
        "symfony/web-server-bundle": "^4.1"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\Tests\": "tests/"
        }
    },
    "replace": {
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": true
        }
    }
}

你的导入路径是正确的,你的composer.json看起来也不错。

尝试删除 vendor 目录,然后尝试启动 composer install

尝试在您的 PHPStorm 中安装 Symfony Plugin

编辑

你的 config/bundles.php 中有下面这行吗?

Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],

此消息告诉您的是,突出显示的 类 仅可用,因为包含它们的包已作为您需要的其他一些包的依赖项安装(在这种情况下,可能是因为 symfony/orm-pack包)。一般来说,依赖这种传递依赖不是我会做的事情。尽管对于 Symfony 包来说这是可以接受的 IMO。

如果您仍然担心此消息,可以通过解压 symfony/orm-pack 来摆脱它(另请参阅 http://fabien.potencier.org/symfony4-unpack-the-packs.html):

$ composer unpack symfony/orm-pack