定制 spryker/code-sniffer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

spryker/code-sniffer

Composer 安装命令:

composer require --dev spryker/code-sniffer

包简介

Spryker Code Sniffer Standards

README 文档

README

CI Latest Stable Version Minimum PHP Version PHPStan License Total Downloads

This sniffer package follows PSR-2 completely and ships with a lot of additional fixers on top (incl. PSR-12). Please see the Spryker Coding conventions for details.

List of included sniffs.

Documentation

See docs.

Upstream docs: squizlabs/PHP_CodeSniffer/wiki

Usage

How to use in Spryker projects

Make sure you include the sniffer as require-dev dependency:

composer require --dev spryker/code-sniffer

The Development module provides a convenience command:

console code:sniff:style

(or console c:s:s as shortcut)

To automatically fix fixable errors, use

console code:sniff:style -f

-v is useful for more info output. To run only a specific sniff, use the -s option. See -h for help.

You can also sniff a specific project level module or path:

console code:sniff:style [-m ModuleName] [optional-sub-path] -v

How to use in any project

You can also manually invoke the phpcs/phpcbf commands:

vendor/bin/phpcs --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml ./
vendor/bin/phpcbf --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml ./

The command phpcs just sniffs, phpcbf fixes.

You probably want to ignore some folders, e.g. --ignore=vendor/ or some of your test fixture folders.

Standards

You can always switch the standard to the stricter one named SprykerStrict. It is an extension of the Spryker standard with its own (strict) sniffs added on top.

How to include in your IDE

E.g. for PHPStorm:

  • Open Settings -> Tools -> External Tools
  • Add a new tool named "cs-sniffer" and set Program to $ProjectFileDir$/vendor/bin/phpcs, Parameters to --standard=$ProjectFileDir$/vendor/spryker/code-sniffer/Spryker/ruleset.xml -p $FilePath$ and Working directory to $ProjectFileDir$.
  • Add a new tool named "cs-fixer" and set Program to $ProjectFileDir$/vendor/bin/phpcbf, Parameters to --standard=$ProjectFileDir$/vendor/spryker/code-sniffer/Spryker/ruleset.xml -v $FilePath$ and Working directory to $ProjectFileDir$.
  • Remove the "Open console" if you don't want to see any output here for the fixer.
  • Now set up your hotkeys under Settings -> Keymap (search for cs-sniffer and cs-fixer). E.g. Control + Comma for sniffing, and Control + Dot for fixing.

You can also set up file watchers, but here you should better only whitelist certain sniffs that only add things and don't remove anything.

How to configure the default rule set

In order to simplify command line interface, phpcs allows to specify default rule set in and standards path the following way.

Assuming the following directory structure:

vendor/spryker/code-sniffer/                          # Base directory
                           |_ Spryker/                # Rule set name
                                      |_ ruleset.xml  # Rule set

The base directory and rule set can be used in configuration now.

vendor/bin/phpcs --config-set installed_paths vendor/spryker/code-sniffer/
vendor/bin/phpcs --config-set default_standard Spryker

You might need to specify full directory path. Now the tools can be used without --standard switch.

Using own project standard

You can exchange or extend the Spryker coding standard by providing your own ruleset.xml. This can be configured in the Development module config:

// DevelopmentConfig.php

    /**
     * Either a relative or full path to the ruleset.xml or a name of an installed
     * standard (see `phpcs -i` for a list of available ones).
     *
     * @return string
     */
    public function getCodingStandard()
    {
        return '/path/to/your/ruleset.xml';
    }

If you use it for custom projects, just use --standard to point to your ruleset file.

Make sure that you include the Spryker core standard ruleset in your custom one, e.g.:

<?xml version="1.0"?>
<ruleset name="SprykerProject">
    <description>
        Spryker Coding Standard for Project.
        Extends main Spryker Coding Standard.
        All sniffs in ./Sniffs/ will be auto loaded
    </description>

    <rule ref="vendor/spryker/code-sniffer/Spryker/ruleset.xml"/>

    <exclude-pattern>*/src/Generated/*</exclude-pattern>
    <exclude-pattern>*/src/Orm/*</exclude-pattern>
    <exclude-pattern>*/tests/_support/_generated/*</exclude-pattern>
    <exclude-pattern>*/tests/_helpers/*</exclude-pattern>
    <exclude-pattern>*/tests/_output/*</exclude-pattern>
    <exclude-pattern>./data/DE/*</exclude-pattern>

    <!-- Define your own sniffs here -->
</ruleset>

If you want to use the SprykerStrict standard in your project, you should replace the string:

<rule ref="vendor/spryker/code-sniffer/Spryker/ruleset.xml"/>

with this one:

<rule ref="vendor/spryker/code-sniffer/SprykerStrict/ruleset.xml"/>

spryker/code-sniffer 适用场景与选型建议

spryker/code-sniffer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.27M 次下载、GitHub Stars 达 38, 最近一次更新时间为 2016 年 02 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「static analysis」 「standards」 「phpcs」 「codesniffer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 spryker/code-sniffer 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 4.27M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 38
  • 点击次数: 27
  • 依赖项目数: 2419
  • 推荐数: 0

GitHub 信息

  • Stars: 38
  • Watchers: 57
  • Forks: 12
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-09