1

I'm working on a Symfony 4 project with PhpStorm 2018.1

It has become common for me to see the use declarations highlighted as if they haven't been installed with composer.

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

The following are installed and show in my composer.json file:

  • stof/doctrine-extensions-bundle
  • symfony/orm-pack

Am I missing something here or is this a PhpStorm issue?

enter image description here

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
        }
    }
}
LazyOne
  • 158,824
  • 45
  • 388
  • 391
Coder1
  • 13,139
  • 15
  • 59
  • 89
  • Could you give us your composer.json ? – D. Schreier Jun 26 '18 at 08:42
  • @D.Schreier it has been posted, thanks for looking. – Coder1 Jun 26 '18 at 08:46
  • See what **xabbuh** have said. It's a special inspection that basically tells that you are using some class that is not directly required in your `composer.json` but by one of the required packages (indirect dependency). The warning makes sense: if tomorrow this package will no longer be required by such package... your code will break. Therefore it's better to add such dependency into your `composer.json`. You can either do what it asks .. or just disable that inspection (if you think it's irrelevant/makes unneeded noise and your code will work fine) – LazyOne Jun 26 '18 at 11:10

2 Answers2

3

What this message is telling you is that the highlighted classes are only available because the packages containing them have been installed as dependencies of some other packages you require (in this case it's probably because of the symfony/orm-pack package). Generally, relying on such transitive dependencies is not something I would do. Though for the Symfony pack that's something acceptable IMO.

If you are still concerned about this message, you can get rid of it by unpacking symfony/orm-pack (see also http://fabien.potencier.org/symfony4-unpack-the-packs.html):

$ composer unpack symfony/orm-pack

xabbuh
  • 5,801
  • 16
  • 18
  • 1
    That is it. The recommended symfony method of installing does this (via composer create-project) and that link on fabian's blog addresses the issue exactly. Thanks. – Coder1 Jun 26 '18 at 14:56
0

Your import path is correct, your composer.json looks good also.

Try to delete the vendor directory then try to launch composer install.

Try to install Symfony Plugin in your PHPStorm.

EDIT

Do you have the line below in your config/bundles.php ?

Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
D. Schreier
  • 1,700
  • 1
  • 22
  • 34
  • The Symfony Plugin was already installed and up to date. I just tried deleting the vendor dir and re-installing but I have the same result. I waited till PS was done re-indexing as well. – Coder1 Jun 26 '18 at 09:01
  • I just edit my answer, could you check if you have the line in your config/bundles.php ? – D. Schreier Jun 26 '18 at 09:02