magento/magento-coding-standard
Composer 安装命令:
composer require magento/magento-coding-standard
包简介
A set of Magento specific PHP CodeSniffer rules.
README 文档
README
A set of Magento rules for PHP_CodeSniffer tool.
Installation within a Magento 2 site
To use within your Magento 2 project you can use:
composer require --dev magento/magento-coding-standard
Due to security, when installed this way the Magento standard for phpcs cannot be added automatically.
You can achieve this by adding the following to your project's composer.json:
"scripts": { "post-install-cmd": [ "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)" ], "post-update-cmd": [ "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)" ] }
Installation for development
You can install Magento Coding Standard by cloning this GitHub repo:
git clone git@github.com:magento/magento-coding-standard.git
cd magento-coding-standard
composer install
It is possible also to install a standalone application via Composer
composer create-project magento/magento-coding-standard --stability=dev magento-coding-standard
Verify installation
Command should return the list of installed coding standards including Magento2.
vendor/bin/phpcs -i
Usage
Once installed, you can run phpcs from the command-line to analyze your code MyAwesomeExtension
vendor/bin/phpcs --standard=Magento2 app/code/MyAwesomeExtension
Fixing issues automatically
Also, you can run phpcbf from the command-line to fix your code MyAwesomeExtension for warnings like "PHPCBF CAN FIX THE [0-9]+ MARKED SNIFF VIOLATIONS AUTOMATICALLY"
vendor/bin/phpcbf --standard=Magento2 app/code/MyAwesomeExtension
Contribution
See the community contribution model.
Where to contribute
- Documentation of existing rules. See ExtDN PHP CodeSniffer rules for Magento 2 as a good example.
- Bug fixes and improvements of existing rules.
- Creation of new PHP CodeSniffer rules.
- Discussions on new rules (through periodic hangouts or discussions per GitHub issue).
How to contribute
- Start with looking into Community Dashboard. Any ticket in
Up for grabsis a good candidate to start. - Didn't satisfy your requirements? Create one of three types of issues:
- Bug report - Found a bug in the code? Let us know!
- Existing rule enhancement - Know how to improve existing rules? Open an issue describe how to enhance Magento Coding Standard.
- New rule proposal - Know how to improve Magento ecosystem code quality? Do not hesitate to open a proposal.
- The issue will appear in the
Backlogcolumn of the Community Dashboard. Once it will be discussed and getacceptedlabel the issue will appear in theUp for grabscolumn.
Testing
All rules should be covered by unit tests. Each Test.php class should be accompanied by a Test.inc file to allow for unit testing based upon the PHP_CodeSniffer parent class AbstractSniffUnitTest.
You can verify your code by running
vendor/bin/phpunit
Also, verify that the sniffer code itself is written according to the Magento Coding Standard:
vendor/bin/phpcs --standard=Magento2 Magento2/ --extensions=php
ESLint
Prerequisites: Node.js (^12.22.0, ^14.17.0, or >=16.0.0).
You need to run the following command to install all the necessary packages described in the package.json file:
npm install
You can execute ESLint as follows:
npm run eslint -- path/to/analyze
RECTOR PHP
From magento-coding-standard project, you can execute rector php as follows:
vendor/bin/rector process Magento2 Magento2Framework PHP_CodeSniffer --dry-run --autoload-file vendor/squizlabs/php_codesniffer/autoload.php
The rules from rector that are applied are set inside the config file: rector.php
The option --dry-run displays errors found, but code is not automatically fixed.
To run rector for magento projects you need to:
- Specify the magento path and the autoload file for the magento project:
vendor/bin/rector process MAGENTO_PATH --dry-run --autoload-file MAGENTO_AUTOLOAD_FILE
Example:
vendor/bin/rector process magento2ce/app/code/Magento/Cms/Model --dry-run --autoload-file magento2ce/vendor/autoload.php
License
Each Magento source file included in this distribution is licensed under the OSL-3.0 license.
Please see LICENSE.txt for the full text of the Open Software License v. 3.0 (OSL-3.0).
magento/magento-coding-standard 适用场景与选型建议
magento/magento-coding-standard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.18M 次下载、GitHub Stars 达 373, 最近一次更新时间为 2019 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 magento/magento-coding-standard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 magento/magento-coding-standard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 14.18M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 375
- 点击次数: 17
- 依赖项目数: 316
- 推荐数: 1
其他信息
- 授权协议: OSL-3.0
- 更新时间: 2019-01-11