pixelfederation/coding-standards 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

pixelfederation/coding-standards

Composer 安装命令:

composer require pixelfederation/coding-standards

包简介

Standardized PHPCS sniffs for backend developers.

README 文档

README

This package provides PHPCS rule set for coding standards in Pixel Federation. It should be included into each project maintained by Pixel Federation that uses PHP Code Sniffer PHPCS.

Migration from v4 to v4.1.0

Generic ruleset was removed. Now there are only rulesets for specific PHP versions.

Replace (in your ruleset) reference to file vendor/pixelfederation/coding-standards/phpcs.ruleset.xml with vendor/pixelfederation/coding-standards/phpcs.ruleset.84.xml for PHP 8.4.

How to use

Install composer dependencies

composer require --dev pixelfederation/coding-standards:^5.0

Supported versions

For each php version there are 2 versions of the ruleset. One for DDD projects and one for Non-DDD projects.

For example for PHP 8.4:

vendor/pixelfederation/coding-standards/phpcs.ruleset.84.xml
OR
vendor/pixelfederation/coding-standards/phpcs.ruleset.84.non-ddd.xml

Ruleset creation

Create a file named phpcs.ruleset.xml in the root folder of your project with the following content:

<?xml version="1.0"?>
<ruleset name="PixelFederation">
  <description>PixelFederation rule set.</description>
    
  <exclude-pattern>tests/</exclude-pattern>

  <rule ref="vendor/pixelfederation/coding-standards/phpcs.ruleset.84.xml"> <!-- Insert version for your php version -->
    <!-- You can exclude some rules here -->
    <exclude name="SlevomatCodingStandard.Files.FunctionLength"/> 
  </rule>
</ruleset>

Running checks

In your project directory run this command:

vendor/bin/phpcs --standard=phpcs.ruleset.xml src

Automatically fixing errors

In your project directory run this command:

vendor/bin/phpcbf --standard=phpcs.ruleset.xml src

Additional links

Sniffs documentation for slevomat coding standards are here: https://github.com/slevomat/coding-standard

GrumPHP

Note: Custom tasks don’t work when using phpro/grumphp-shim (PHAR) with parallel.enabled: true due to class serialization limitations. If you need custom tasks, install GrumPHP via Composer.

Tasks

Installation

# grumphp.yml
grumphp:
    extensions:
        - PixelFederation\CodingStandards\GrumPHP\ExtensionLoader

Doctrine ORM Mapping Validation

# grumphp.yml
grumphp:
    tasks:
        doctrine_schema_validate:
            skip_mapping: false
            skip_sync: false
            skip_property_types: false
            em: default
            triggered_by: ['php', 'xml', 'yml']

For multiple entity managers you can specify the entity manager to be used:

# grumphp.yml
grumphp:
    tasks:
        doctrine_schema_validate_application:
            em: application
            metadata:
                task: doctrine_schema_validate
        doctrine_schema_validate_reporting:
            em: reporting
            metadata:
                task: doctrine_schema_validate

console_path

Default: 'bin/console'

With this parameter you can set the path of the console to be used.

skip_mapping

Default: false

With this parameter you can skip the mapping validation check.

skip_sync

Default: false

With this parameter you can skip checking if the mapping is in sync with the database.

triggered_by

Default: [php, xml, yml]

This is a list of extensions that should trigger the Doctrine task.

em

Default: null

Require doctrine/orm >= 3.0. Specify the entity manager to be used. If not set, the default entity manager will be used.

skip_property_types

Default: null

Require doctrine/orm >= 3.0. With this parameter you can skip checking if property types match the Doctrine types.

Composer Install Check

# grumphp.yml
grumphp:
    tasks:
        composer_install_check:
            script: './vendor/pixelfederation/coding-standards/bin/composer_install_check.sh',
            ignore_patterns: []
            triggered_by: ['php', 'yml', 'yaml', 'xml']
            whitelist_patterns: []
            metadata:
                priority: 900

script

Default: './bin/composer_install_check.sh'

Path to check script.

ignore_patterns

Default: []

This is a list of patterns that will be ignored by phpcs. With this option you can skip files like tests. Leave this option blank to run phpcs for every php file.

triggered_by

Default: ['php', 'yml', 'yaml', 'xml']

This is a list of extensions to be sniffed.

whitelist_patterns

Default: []

This is a list of regex patterns that will filter files to validate. With this option you can skip files like tests. This option is used in relation with the parameter triggered_by.

PhpMd Extended

Extends the default PhpMd task and splits the files into smaller chunks to prevent the Argument list too long error.

Config

The task lives under the phpmd_extended namespace and has following configurable parameters:

# grumphp.yml
grumphp:
    tasks:
        phpmd_extended:
            whitelist_patterns: []
            exclude: []
            report_format: text
            ruleset: ['cleancode', 'codesize', 'naming']
            triggered_by: ['php']
            chunks_size: 1000

chunk_size

Default: 1000

This parameter defines how many files will be checked in one execution of phpmd. This can help with performance on large codebases.

PHPStan Extended

Extends the default PHPStan task and splits the files into smaller chunks to prevent the Argument list too long error.

Config

The task lives under the phpstan_extended namespace and has following configurable parameters:

# grumphp.yml
grumphp:
    tasks:
        phpstan_extended:
            autoload_file: ~
            chunk_size: 1000
            configuration: ~
            level: null
            force_patterns: []
            ignore_patterns: []
            triggered_by: ['php']
            memory_limit: "-1"
            use_grumphp_paths: true

chunk_size

Default: 1000

This parameter defines how many files will be checked in one execution of phpstan. This can help with performance on large codebases.

XmlLint Extended

Extends the default XmlLint task with strict schema validation. Require ext-dom and ext-libxml extensions.

Config

It lives under the xmllint_extended namespace and has following configurable parameters:

# grumphp.yml
grumphp:
    tasks:
        xmllint_extended:
            ignore_patterns: []
            load_from_net: false
            x_include: false
            dtd_validation: false
            scheme_validation: false
            triggered_by: ['xml']

pixelfederation/coding-standards 适用场景与选型建议

pixelfederation/coding-standards 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 81.86k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 81.86k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 15
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 5
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2021-08-13