Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPStorm unable to run phpcs inspection #390

Open
Vinai opened this issue May 11, 2022 · 12 comments · May be fixed by #436
Open

PHPStorm unable to run phpcs inspection #390

Vinai opened this issue May 11, 2022 · 12 comments · May be fixed by #436
Assignees
Labels
bug Something isn't working Progress: PR created

Comments

@Vinai
Copy link

Vinai commented May 11, 2022

Preconditions

  1. Tested on Magento Open Source 2.4.4 and Adobe Commerce 2.4.4
  2. PHP 8.1 (I haven't tried 7.4)
  3. PHPStorm version is 2021.2.4

Steps to reproduce

  1. Configure PHP interpreter in PHPStorm
  2. Configure phpcs in PHPStorm to use the Magento coding standard
  3. Enable the phpcs inspections

Expected result

  1. PHPStorm displays phpcs rule violations according to the configuration

Actual result

In the PHStorm event log the message is shown

ERROR: Referenced sniff "PHPCompatibility.FunctionUse.RemovedFunctions" does not exist

Additional Information

Running phpcs on the command line works

vendor/bin/phpcs --standard=vendor/magento/magento-coding-standard/Magento2 path/to/check

The same PHPStorm configuration works on Magento 2.4.3 with PHP 7.4.


If I remove the reference to that sniff from the Magento2/ruleset.xml, phpcs fails with a stacktrace where any other Magento2 rule extending from a PHPCompatibility rule class can't find the parent class.
Maybe this points to an autoload error?
However, I quick test by adding "PHPCompatibility\\:": "vendor/phpcompatibility/php-compatibility/PHPCompatibility/" to the root composer.json and dumping the composer autoloader did not change anything.

@Vinai Vinai added the bug Something isn't working label May 11, 2022
@m2-assistant
Copy link

m2-assistant bot commented May 11, 2022

Hi @Vinai. Thank you for your report.
To speed up processing of this issue, make sure that you provided sufficient information.

Add a comment to assign the issue: @magento I am working on this


@rafafortes
Copy link

I'm facing the same issue. My PHPStorm version is: 2022.1

@tuyennn
Copy link
Member

tuyennn commented Jun 2, 2022

For somehow $installedPath ../../phpcompatibility/php-compatibility was missing during inspecting code on PHPStorm but it doesn't while using cli

@fiko
Copy link

fiko commented Jul 20, 2022

it's not permanent fixing, but you may apply this patch @tuyennn @Vinai https://gist.github.com/fiko/bdec71978b458cc527df03d26a695b6c

@MeCapron
Copy link

I'm facing the same issue. Any news on this?

@snoop0x7b
Copy link
Contributor

Any update on this? PHPCS is an important part of our workflow.

@sivaschenko
Copy link
Member

To include Magento Coding Standard as part of PHPStorm inspections, follow the steps:

  • Open PHPStorm preferences
  • Navigate to "Editor" | "Inspections"
  • Select "PHP" | "Quality Tools" | "PHP_CodeSniffer validation"
  • Set "Coding standard" to "Custom" and select path to <project_root>/vendor/magento/magento-coding-standard/Magento2/ruleset.xml
  • Check "Installed standards path" and select path to <project_root>/vendor/php-compatibility/PHPCompatibility

PR adding these instructions to the documentation: AdobeDocs/commerce-php#48

@lfolco
Copy link

lfolco commented Jan 16, 2023

I'm seeing this issue when running on CLI too

@sprankhub
Copy link
Member

Did anyone find a proper fix for this? For us, it is only happening in our pipepline, but not locally. https://gist.github.com/fiko/bdec71978b458cc527df03d26a695b6c is rather hacky.

@fredden
Copy link
Member

fredden commented Feb 13, 2024

@sprankhub I fixed this locally by un-setting the 'installed_paths' option within PHPStorm, and relying instead on the installer plug-in. Are you perhaps running your pipeline as root? If so, you'll need to (either switch to a non-root user or) tell Composer that you really want to run plug-ins with https://getcomposer.org/doc/03-cli.md#composer-allow-superuser

@sprankhub
Copy link
Member

@fredden thanks, buddy! Using COMPOSER_ALLOW_SUPERUSER indeed fixed it 🎉

@gowrizrh
Copy link

I ran into this issue on 2.4.6-p3 and had to modify the composer script bit

"scripts": {
    "post-install-cmd": [
      "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/,../../magento/php-compatibility-fork)"
    ],
    "post-update-cmd": [
      "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/,../../magento/php-compatibility-fork)"
    ]
}

I don't know at what point the paths changed from phpcompatibility/php-compatibility to magento/php-compatibility-fork but inspections now work on my PHPStorm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Progress: PR created
Projects
Status: Pull Request In Progress
Development

Successfully merging a pull request may close this issue.