phpcode 嗅探器无法在 Magento 模块中运行

phpcode sniffer unable to run in magento module

提问人:footy 提问时间:2/10/2023 更新时间:2/10/2023 访问量:193

问:

我正在尝试在我的 magento 模块项目中安装 phpcodesniffer。以下是我的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\\": ""
      }
    }
  }

现在我可以在我的文件夹中成功运行 composer update/install。但是,当我运行该命令时,我收到如下错误vendor/bin/phpcs --standard=Magento2 ./

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 

如何在这里运行php代码嗅探器?

composer-php magento2 phpcodesniffer

评论

0赞 footy 2/10/2023
我尝试运行composer require magento/framework,但找不到任何这样的依赖项。什么是正确的依赖关系?
0赞 AD7six 2/10/2023
等一下:) 这个问题听起来更像是模块本身没有声明依赖项 - 这只是第一次尝试加载它。not found in … Test/Module/registration.php
0赞 footy 2/11/2023
你是什么意思?我是magento的新手。模块应该如何声明依赖关系
1赞 AD7six 2/11/2023
请在问题中添加以澄清您询问的代码。你刚才问的问题不是磁电机特有的Test/Module/registration.php
1赞 hakre 2/11/2023
我也和@AD7six在一起,在我看来是触发它的,如果不显示它的代码,我无法提出任何好的建议。"files": [ "registration.php" ],

答: 暂无答案