定制 dvsa/coding-standards 二次开发

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

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

dvsa/coding-standards

Composer 安装命令:

composer require dvsa/coding-standards

包简介

Coding Standards used for PHP in the Driver and Vehicle Standards Agency. PSR Compliant.

README 文档

README

A custom ruleset for PHP CodeSniffer and PHP-CS-Fixer for use in the Driver and Vehicles Standard Agency (DVSA). PHP Coding standards are maintained and updated by the developer community at the DVSA. See CONTRIBUTING.md for more information how make changes.

Prerequisites

Installation

composer require --dev dvsa/coding-standards

or if you install the coding standard tools globally use:

composer require global dvsa/coding-standards

How to set up

Refer to the Integrations or How to run section for help with running/integrating in with code editors/IDE.

PHP CodeSniffer

Repository: https://github.com/PHPCSStandards/PHP_CodeSniffer.

  1. Create a phpcs.dist.xml file in the root directory of your project. Example:
    <?xml version="1.0"?>
    <ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="DVSA" xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">
      <file>./path/to/directory</file>
      <file>./path/to/file.php</file>
    
      <exclude-pattern>*/vendor/*</exclude-pattern>
    
      <rule ref="./vendor/dvsa/coding-standards/src/Profiles/DVSA/CS/ruleset.xml" />
    </ruleset>

XML reference.

PHP-CS-Fixer

Repository: https://github.com/FriendsOfPHP/PHP-CS-Fixer.

Due to the number of dependencies in php-cs-fixer it must be installed manually.

  1. Recommended way to install using composer-bin-plugin.
    $ composer require --dev bamarni/composer-bin-plugin
  2. Install php-cs-fixer. It is recommended to install PHP-CS-Fixer in a separate working directory:
    $ composer bin php-cs-fixer require friendsofphp/php-cs-fixer dvsa/coding-standards
  3. Create a .php-cs-fixer.dist.php file in the root directory of your project.
  4. Add .php-cs-fixer.cache to your .gitignore. The cache filename can be changed using the $cacheFilename parameter (default: .php-cs-fixer.cache).
  5. Configure and return a PhpCsFixer\ConfigInterface object. This repository provides a preconfigured class:
    <?php
    $cacheFilename = '.php-cs-fixer.cache';
    
    $finder = PhpCsFixer\Finder::create()
        ->exclude('vendor')
        ->in(__DIR__);
    
    // Any additional project rules/rule sets.
    $additionalRules = [
        // Rule sets
        '@PHP80Migration:risky' => true,
        '@PHP81Migration' => true,
        '@Symfony' => true,
        '@Symfony:risky' => true,
        // Individual rules
        'protected_to_private' => false,
    ];
    
    return (new \Dvsa\PhpCodingStandards\PhpCsFixer\Config())($finder, $additionalRules, $cacheFilename);

Tip: Add .php-cs-fixer.php to your .gitignore to enable additional rules locally.

How to run

GitHooks

Recommended using a tool to handle the GitHooks functionality due to the manual steps to set up hooks (symlinks/copying). Lots of tools can be used to handle GitHooks.

Husky & lint-staged (NPM)

Repositories: Husky & lint-staged package.

  1. Install using NPM:
$ npm i --save-dev husky lint-staged
  1. Configure Husky:
$ npm set-script prepare "husky install"
$ npm run prepare
  1. Create .lintstagedrc:
{
   "**/*.php": [
      "php ./vendor/bin/php-cs-fixer fix --diff --quiet",
      "php ./vendor/bin/phpcs --standard=./phpcs.dist.xml --report=diff --colors"
   ]
}
  1. Add lint-staged to the pre-commit hook:
$ npx husky add .husky/pre-commit "lint-staged"

The above pre-commit hook will utilise both PHP-CS-Fixer and PHPCS. The fixer will be run before PHP CodeSniffer.

Integrations

JetBrains (IntelliJ/PHPStorm)

JetBrains have comprehensive documentation for setting up code quality tools.

PHP CodeSniffer path to ruleset: /phpcs.dist.xml PHP CS Fixer path to ruleset: /.php-cs-fixer.dist.php

Licence

See LICENSE.md

Contributing

See CONTRIBUTING.md

Acknowledgements

This coding standard is a tweak on top of the PSR2 standard and only possible because of that. However particularly the time and effort of Chris Emerson BJSS is acknowledged for tidying this and working on it during his time on the VOL project.

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 61.51k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 26
  • 依赖项目数: 11
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-06-13