I am trying to install phpcodesniffer in my magento module project. Below is my composer.json
{
"name": "test/myModule",
"description": "testin",
"type": "magento2-module",
"version": "1.0.0",
"require": {
"php": "^8.1"
},
"require-dev": {
"squizlabs/php_codesniffer": "3.*",
"magento/magento-coding-standard": "^31.0"
},
"autoload": {
"files": [ "registration.php" ],
"psr-4": {
"Test\\Module\\": ""
}
}
}
Now I can successfully run composer update/install in my folder. However when I run the command vendor/bin/phpcs --standard=Magento2 ./
I get an error like below
PHP Fatal error: Uncaught Error: Class "Magento\Framework\Component\ComponentRegistrar" not found in /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/registration.php:2
Stack trace:
#0 /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/vendor/composer/autoload_real.php(55): require()
#1 /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/vendor/composer/autoload_real.php(38): composerRequireabd7530303d7978f314768d362cfeb3f()
#2 /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/vendor/autoload.php(25): ComposerAutoloaderInitabd7530303d7978f314768d362cfeb3f::getLoader()
#3 /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/vendor/squizlabs/php_codesniffer/autoload.php(79): include('...')
#4 /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/vendor/squizlabs/php_codesniffer/bin/phpcs(17): PHP_CodeSniffer\Autoload::load()
#5 /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/vendor/bin/phpcs(120): include('...')
#6 {main}
thrown in /home/cloudpanel/htdocs/magento2.mgt/app/code/Test/Module/registration.php on line 2
How can I run the php codesniffer here?