承接 magento-ecg/coding-standard 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

magento-ecg/coding-standard

Composer 安装命令:

composer require magento-ecg/coding-standard

包简介

A set of PHP_CodeSniffer rules and sniffs.

README 文档

README

SensioLabsInsight Medal

ECG Magento Code Sniffer Coding Standard is a set of rules and sniffs for PHP_CodeSniffer tool.

It allows automatically check your code against some of the common Magento and PHP coding issues, like:

  • raw SQL queries;
  • SQL queries inside a loop;
  • direct instantiation of Mage and Enterprise classes;
  • unnecessary collection loading;
  • excessive code complexity;
  • use of dangerous functions;
  • use of PHP Superglobals;

and many others.

Both Magento and Magento 2 are supported.

Installation

Before starting using our coding standard install PHP_CodeSniffer.

The recommended installation method for PHPCS is globally with Composer:

composer global require "squizlabs/php_codesniffer=*"

Make sure Composer's bin directory (defaulted to ~/.composer/vendor/bin/) is in your PATH.

Clone or download this repo somewhere on your computer or install it with Composer:

composer require magento-ecg/coding-standard

Note: PHP_CodeSniffer 3.x is now required to run our coding standard. To install PHP_CodeSniffer 2.x compatible version:

composer require magento-ecg/coding-standard:4.*

Add the ECG standards directory to PHP_CodeSniffer's installed paths:

$ ./vendor/bin/phpcs --config-set installed_paths /path/to/your/folder/vendor/magento-ecg/coding-standard

You can check Installation by running following command:

$ ./vendor/bin/phpcs -i

It should do the following output:

The installed coding standards are EcgM2, PEAR, Zend, PSR2, MySource, Squiz, PSR1, PSR12 and Magento2

Usage CLI Tool

Select a standard to run with CodeSniffer: EcgM2 for Magento 2

Run CodeSniffer:

$ ./vendor/bin/phpcs --standard=EcgM2,PSR2,Magento2 /path/to/code

This package is compatible with Composer Installer Plugins for PHPCS coding standards (such as https://github.com/Dealerdirect/phpcodesniffer-composer-installer) and can be automatically registered with PHPCS during installation.

To check design templates, you must specify phtml in the --extensions argument: --extensions=php,phtml

Usage Hook pre-commit

Get hook file from the existing repository.

$ /path/to/your/folder/vendor/magento-ecg/coding-standard/.githooks

Install Hooks on the project. Copy hook into the project GIT folder

cp -R ./vendor/magento-ecg/coding-standard/.githooks ./

To automate hooks installation for all developers, it needs to include the following lines into your project's composer.json

    "scripts": {
        "post-install-cmd": [
            "git config core.hooksPath .githooks"
        ],
        "post-update-cmd": [
            "git config core.hooksPath .githooks"
        ]
    }

Run composer install to refresh the project state.

composer install

You are done! Now, each product commit will be validated for an alignment with Magento Coding Standards.

Usage PHPStorm

PhpStorm provides code style check through integration with the PHP Code Sniffer tool, which validates your code for consistency with a coding standard and best practices.

Once Tool installed and configured in PhpStorm, the tool is available in any opened PHP file. Errors and warnings reported by PHP Code Sniffer on-the-fly are displayed as popup messages.

Install coding standard for development See Installation steps.

Configure PhpStorm

  • Open Preference: "Settings > Preferences > Editor > Inspections > PHP > Quality Tools".
  • Choose "PHP_CodeSniffer validation" option.
  • It is ok to configure everything under the scope "Everything else":
  • In the "Check files with extensions" field, provide the comma-separated list of file extensions that should be checked by PHP Code Sniffer: php, js, phtml.
  • Installed standard path should be checked and selected project path
/path/to/your/folder/vendor/magento-ecg/coding-standard
  • Choose installed coding standard path as the main for standards
  • Select "EcgM2" or "Custom" it the "Coding standard" list.

PHP Storm

https://www.jetbrains.com/help/phpstorm/using-php-code-sniffer.html#installing-configuring-code-sniffer

Note: We would also suggest enabling PHP Mess Detector validation as well. Note: in case of using a Docker or VM, It needs to configure new PHPCS CLI Interpreter which will point out to VM/Docker.

Requirements

PHP 5.4 and up.

Checkout the php-5.3-compatible branch to get the PHP 5.3 version.

Contribution

Please feel free to contribute new sniffs or any fixes or improvements for the existing ones.

magento-ecg/coding-standard 适用场景与选型建议

magento-ecg/coding-standard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.68M 次下载、GitHub Stars 达 309, 最近一次更新时间为 2013 年 09 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 magento-ecg/coding-standard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 magento-ecg/coding-standard 我们能提供哪些服务?
定制开发 / 二次开发

基于 magento-ecg/coding-standard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.68M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 313
  • 点击次数: 22
  • 依赖项目数: 61
  • 推荐数: 0

GitHub 信息

  • Stars: 309
  • Watchers: 43
  • Forks: 95
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-09-04