0

I keep getting "Multiple definitions exist for class..." warnings in PhpStorm, and upon inspection, I see these a bunch of these huge php-cs-fixer files (100K+ lines) with the comment "This file is part of PHP CS Fixer.".

I found that there are multiple copies of several other files named phploc, composer, php-scoper, etc., under vendor/library_name/tools/ in various libraries for some reason. They are all huge compiled files that PhpStorm detects.

I tried ignoring these files in PhpStorm one by one, and once re-indexing finishes, these files disappear, leading me to believe they're IDE-generated files. However, it makes no sense the IDE would generate them and in turn include them hinting code.

enter image description here

enter image description here

composer.json

{
    "name": "magento/project-community-edition",
    "description": "eCommerce Platform for Growth (Community Edition)",
    "type": "project",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "config": {
        "preferred-install": "dist",
        "sort-packages": true
    },
    "require": {
        "magento/composer-root-update-plugin": "~1.0",
        "magento/product-community-edition": "2.4.1"
    },
    "require-dev": {
        "allure-framework/allure-phpunit": "~1.2.0",
        "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
        "friendsofphp/php-cs-fixer": "~2.16.0",
        "lusitanian/oauth": "~0.8.10",
        "magento/magento-coding-standard": "*",
        "magento/magento2-functional-testing-framework": "^3.0",
        "pdepend/pdepend": "~2.7.1",
        "phpcompatibility/php-compatibility": "^9.3",
        "phpmd/phpmd": "^2.8.0",
        "phpstan/phpstan": ">=0.12.3 <=0.12.23",
        "phpunit/phpunit": "^9",
        "sebastian/phpcpd": "~5.0.0",
        "squizlabs/php_codesniffer": "~3.5.4"
    },
    "conflict": {
        "gene/bluefoot": "*"
    },
    "autoload": {
        "psr-4": {
            "Magento\\Framework\\": "lib/internal/Magento/Framework/",
            "Magento\\Setup\\": "setup/src/Magento/Setup/",
            "Magento\\": "app/code/Magento/",
            "Zend\\Mvc\\Controller\\": "setup/src/Zend/Mvc/Controller/"
        },
        "psr-0": {
            "": [
                "app/code/",
                "generated/code/"
            ]
        },
        "files": [
            "app/etc/NonComposerComponentRegistration.php",
            "app/helper.php"
        ],
        "exclude-from-classmap": [
            "**/dev/**",
            "**/update/**",
            "**/Test/**"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Magento\\Sniffs\\": "dev/tests/static/framework/Magento/Sniffs/",
            "Magento\\Tools\\": "dev/tools/Magento/Tools/",
            "Magento\\Tools\\Sanity\\": "dev/build/publication/sanity/Magento/Tools/Sanity/",
            "Magento\\TestFramework\\Inspection\\": "dev/tests/static/framework/Magento/TestFramework/Inspection/",
            "Magento\\TestFramework\\Utility\\": "dev/tests/static/framework/Magento/TestFramework/Utility/",
            "Magento\\PhpStan\\": "dev/tests/static/framework/Magento/PhpStan/"
        }
    },
    "version": "2.4.0",
    "minimum-stability": "stable",
    "repositories": [
        {
            "type": "composer",
            "url": "https://repo.magento.com/"
        }
    ],
    "extra": {
        "magento-force": "override"
    }
}

PhpStorm ignored files (adding php-cs-fixer and phploc here somehow removed all/multiple copies from the vendor directories): enter image description here

laketuna
  • 3,832
  • 14
  • 59
  • 104
  • Uh, that's strange. Looks like you have some `dev` dependency installed that has those duplicates. Try inspecting your composer.json & replacing the dev versions with stable ones. – Dmitrii Oct 27 '20 at 13:48
  • Don't think they're dev dependencies. They seem to be IDE generated files. Updated post. – laketuna Oct 28 '20 at 02:22
  • 1
    No, IDE doesn't generate those: we don't have any related features, there are also no similar problems on our bug tracker/ticket system. Is it possible to share your composer.json? – Dmitrii Oct 28 '20 at 10:07
  • @Dmitrii I see. I updated the post with `composer.json` and my PhpStorm ignored file list. – laketuna Oct 28 '20 at 22:12
  • Thanks! Installed everything but Magento (requires authentication) - didn't have such problem. As a test you can try creating this project in an empty directory & check if the same happens. If it does - most likely this is coming from those magento packages. – Dmitrii Oct 29 '20 at 17:21

1 Answers1

0

These files are in your vendor directory as you must have install your dependencies from sources, not distributions.

Let's use sebastian/code-unit as an example to see how it works:

So, you must have install your dependencies using composer install --prefer-source (or composer update --prefer-source as it's the other command with that option) and you want to use --prefer-dist or actually not using any of these flags as the latter is the default. You can find more information about it in official documentation: https://getcomposer.org/doc/03-cli.md#install-i

Remove your vendor directory and install dependencies once more without --prefer-source flag.

AFAIR there was also an issue when you did not have curl extension installed, then simply add this extension.

kuba
  • 3,670
  • 3
  • 31
  • 41