承接 wayofdev/cs-fixer-config 相关项目开发

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

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

wayofdev/cs-fixer-config

Composer 安装命令:

composer require wayofdev/cs-fixer-config

包简介

🧹 Adds custom rule-sets to PHP CS Fixer for consistent coding standards.

README 文档

README


WayOfDev Logo

Build
Build Status

Project
Total Downloads Latest Stable Version Commits since latest release PHP Version Require

Quality
Codecov Mutation testing badge PHP Stan Level 9 of 9

Community
Discord Follow on Twitter (X)


PHP CS Fixer Config

Wrapper with pre-defined rules around the PHP-CS-Fixer package — A tool to automatically fix PHP Coding Standards issues.

This repository aims to provide a standardized way to apply coding standards across multiple projects, ensuring consistency and adherence to best practices. By using predefined rulesets, it simplifies the setup process and allows teams to quickly integrate PHP-CS-Fixer into their development workflow.


If you like/use this package, please consider ⭐️ starring it. Thanks!


📜 Custom Rulesets

WayOfDev\PhpCsFixer\Config\RuleSets\DefaultRuleset::class

Based on @Symfony ruleset

WayOfDev\PhpCsFixer\Config\RuleSets\ExtendedPERSet::class

Based on @PER-CS2.0 ruleset


💿 Installation

→ Using composer

Require as dependency:

composer req --dev wayofdev/cs-fixer-config

🛠 Configuration

→ Setup

  • Create PHP file and name it .php-cs-fixer.dist.php and place it inside root directory of project. It will be recognized by PHP CS Fixer automatically.

  • Example contents of .php-cs-fixer.dist.php file:

     <?php
    
     declare(strict_types=1);
    
     use WayOfDev\PhpCsFixer\Config\ConfigBuilder;
     use WayOfDev\PhpCsFixer\Config\RuleSets\DefaultSet;
    
     require_once 'vendor/autoload.php';
    
     $config = ConfigBuilder::createFromRuleSet(new DefaultSet())
         ->inDir(__DIR__ . '/src')
         ->inDir(__DIR__ . '/tests')
         ->addFiles([__FILE__])
         ->getConfig()
     ;
    
     $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php-cs-fixer.cache');
    
     return $config;

→ Composer Script

  • Add scripts section to composer.json:

    {
        "scripts": {
    +       "cs:diff": "php vendor/bin/php-cs-fixer fix --dry-run -v --diff",
    +       "cs:fix": "php vendor/bin/php-cs-fixer fix -v"
        }
    }

→ Git

  • Place .build folder file into .gitignore

    +/.build/
     /vendor/

→ Makefile

  • If you are using Makefile, create a Makefile with a lint-php and lint-diff targets:

    +APP_RUNNER ?= php
    +APP_COMPOSER ?= $(APP_RUNNER) composer
    +
    +prepare:
    +  mkdir -p .build/php-cs-fixer
    +.PHONY: prepare
    
    +lint-php: prepare ## Fixes code to follow coding standards using php-cs-fixer
    +  $(APP_COMPOSER) cs:fix
    +.PHONY: lint-php
    
    +lint-diff: prepare ## Runs php-cs-fixer in dry-run mode and shows diff which will by applied
    +  $(APP_COMPOSER) cs:diff
    +.PHONY: lint-diff

Or, you can check for one of our pre-configured Makefile from any of these repositories:

https://github.com/wayofdev/php-cs-fixer-config/blob/master/Makefile

https://github.com/wayofdev/laravel-package-tpl/blob/master/Makefile

→ GitHub Actions

  • To use this package in GitHub Actions, add a coding-standards.yml workflow to your repository:

    ---
    
    on:  # yamllint disable-line rule:truthy
      pull_request:
        branches:
          - master
      push:
        branches:
          - master
    
    name: 🧹 Fix PHP coding standards
    
    jobs:
      coding-standards:
        timeout-minutes: 4
        runs-on: ${{ matrix.os }}
        concurrency:
          cancel-in-progress: true
          group: coding-standards-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
        strategy:
          matrix:
            os:
              - ubuntu-latest
            php-version:
              - '8.1'
            dependencies:
              - locked
        permissions:
          contents: write
        steps:
          - name: ⚙️ Set git to use LF line endings
            run: |
              git config --global core.autocrlf false
              git config --global core.eol lf
    
          - name: 🛠️ Setup PHP
            uses: shivammathur/setup-php@2.30.4
            with:
              php-version: ${{ matrix.php-version }}
              extensions: none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter
              ini-values: error_reporting=E_ALL
              coverage: none
    
          - name: 📦 Check out the codebase
            uses: actions/checkout@v4.1.5
    
          - name: 🛠️ Setup problem matchers
            run: |
              echo "::add-matcher::${{ runner.tool_cache }}/php.json"
    
          - name: 🤖 Validate composer.json and composer.lock
            run: composer validate --ansi --strict
    
          - name: 🔍 Get composer cache directory
            uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0
    
          - name: ♻️ Restore cached dependencies installed with composer
            uses: actions/cache@v4.0.2
            with:
              path: ${{ env.COMPOSER_CACHE_DIR }}
              key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
              restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
    
          - name: 📥 Install "${{ matrix.dependencies }}" dependencies with composer
            uses: wayofdev/gh-actions/actions/composer/install@v3.1.0
            with:
              dependencies: ${{ matrix.dependencies }}
    
          - name: 🛠️ Prepare environment
            run: make prepare
    
          - name: 🚨 Run coding standards task
            run: composer cs:fix
            env:
              PHP_CS_FIXER_IGNORE_ENV: true
    
          - name: 📤 Commit and push changed files back to GitHub
            uses: stefanzweifel/git-auto-commit-action@v5.0.1
            with:
              commit_message: 'style(php-cs-fixer): lint php files and fix coding standards'
              branch: ${{ github.head_ref }}
              commit_author: 'github-actions <github-actions@users.noreply.github.com>'
            env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Or, you can check for one of our pre-configured workflows from any of these repositories:

https://github.com/wayofdev/php-cs-fixer-config/blob/master/.github/workflows/coding-standards.yml


💻 Usage

Fix coding standards by simply running console command:

→ Directly

vendor/bin/php-cs-fixer fix -v

→ Via Composer Script

To use via composer script commands:

  • Fixes code to follow coding standards using php-cs-fixer:

    composer cs:diff
  • Runs php-cs-fixer in dry-run mode and shows diff which will by applied:

    composer cs:fix

→ Using Makefile

To use with Makefile

  • Fixes code to follow coding standards using php-cs-fixer:

    make lint-php
  • Runs php-cs-fixer in dry-run mode and shows diff which will by applied:

    make lint-diff

🔒 Security Policy

This project has a security policy.


🙌 Want to Contribute?

Thank you for considering contributing to the wayofdev community! We are open to all kinds of contributions. If you want to:

You are more than welcome. Before contributing, kindly check our contribution guidelines.

Conventional Commits


🫡 Contributors

Contributors Badge

🌐 Social Links


🧱 Resources


⚖️ License

Licence


wayofdev/cs-fixer-config 适用场景与选型建议

wayofdev/cs-fixer-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 66.46k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2022 年 07 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 wayofdev/cs-fixer-config 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 66.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 23
  • 依赖项目数: 14
  • 推荐数: 1

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-15