I use PHPStorm and have the following message "Multiple definitions" for the PHPUnit\Framework\TestCase
. I am not sure exactly but it looks like PHPStorm used compose autoload system. So I tried to find directories where unnecessary class definitions live and exclude them.
I found that I can use exclude-from-classmap
property in autoload
. So I added the following to it:
"vendor/cloudinary/cloudinary_php/tests/",
"vendor/bin/.phpunit/phpunit-5.7/src/ForwardCompatibility/"
These are directories where unnecessary class definitions exist. Then I ran composer dump-autoload
. Nothing changed. Restarted PHPStrom - nothing.
Here is my whole autoload section:
"autoload": {
"psr-4": { "": "src/" },
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ],
"files": [
"src/helpers/helpers.php"
],
"exclude-from-classmap": [
"vendor/cloudinary/cloudinary_php/tests/",
"vendor/bin/.phpunit/phpunit-5.7/src/ForwardCompatibility/"
]
},
I noticed related questions but they do not meet my requirements. I know that the way to exclude folder from composer.
PhpStorm doesn't care too much about your composer.json
*. It founds the class defined two times in the files of your project and this is the reason it warns you.
PHP is not bothered about the class being defined two times. If it loads the class from one file (through the autoloader generated by Composer), it never reads the other file.
After you detect the duplicates and decide which one you want PhpStorm to ignore, right-click on its directory in Project View and choose "Mark Directory as" -> "Excluded" from the menu that appears.
* This is not entirely true. PhpStorm by default is configured to add as libraries the packages it finds in the Composer files in the project. But it warns about duplicate definitions of classes even in the absence of Composer files in the project.
You are working with multiple modules, i.e. multiple "projects" in a single "workspace" right?
PHPStorm doesn't really support that. It lets you open multiple projects in a single workspace, but doesn't really support that style of working. The support is thoroughly broken, fragmentary, and whatever of it exists, seems hacked-in on top of a fundamentally incompatible design. This is just the sad state of affairs that continues into 2019 2020, and there is no light at the end of the tunnel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With