承接 adachsoft/php-code-style 相关项目开发

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

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

adachsoft/php-code-style

最新稳定版本:v0.2.1

Composer 安装命令:

composer require adachsoft/php-code-style

包简介

Shared PHP code style (PHP-CS-Fixer) and PHPStan baseline for PHP 8.3+ projects

README 文档

README

Shared PHP code style (PHP-CS-Fixer) and PHPStan configuration for PHP 8.3+ projects.

Namespaces used in this package follow AdachSoft... vendor prefix.

What this package provides

  • PHP-CS-Fixer ruleset aligned with PSR-12 plus project conventions:
    • php_unit_method_casing: camelCase
    • declare_strict_types
    • fully_qualified_strict_types: import_symbols=false
    • ordered_imports
    • trailing_comma_in_multiline for arguments, arrays, parameters
    • single_quote
    • blank_line_before_statement for return
  • PHPStan baseline config (level 9) ready to analyse src/ (compatible with PHPStan 2.x).

Requirements

  • PHP 8.3+
  • Your project should have dev tools installed: friendsofphp/php-cs-fixer and phpstan/phpstan (this package only provides configuration).

Install

  • Require this package as a dev dependency in your project: composer require --dev adachsoft/php-code-style
  • If needed, also require the tools in your project: composer require --dev friendsofphp/php-cs-fixer phpstan/phpstan

How to use in your project 1) PHP-CS-Fixer

  • Create (or update) a .php-cs-fixer.php file in your project root that imports this package's rules and applies them to your project tree. Example:
    • Load the config from this package
    • Replace the Finder to point at your project (so it scans your code, not the vendor directory)
    • Optionally extend/override rules to fit your needs

2) PHPStan

  • EITHER let phpstan/extension-installer include our config automatically via composer extra:
    • This package declares extra.phpstan.includes in its composer.json
    • If your project uses phpstan/extension-installer, our phpstan.neon.dist will be auto-included
  • OR include manually in your project's phpstan.neon: includes:
    • vendor/adachsoft/php-code-style/phpstan.neon.dist parameters: paths:
      • src

        Optional: configure minimum variable length rule

        adachsoftMinVariableLength: 3

Composer scripts (recommended in your project)

  • In your project's composer.json add: scripts: cs:check: php-cs-fixer fix --dry-run --diff --config=.php-cs-fixer.php cs:fix: php-cs-fixer fix --config=.php-cs-fixer.php stan: phpstan analyse

Setup script

  • This package ships with a helper script to configure your project quickly: vendor/bin/code-style-setup
  • It will:
    • backup existing .php-cs-fixer(.dist).php and phpstan(.neon|.neon.dist)
    • write project .php-cs-fixer.php importing rules from this package and setting the Finder to your paths (default: src, tests)
    • write phpstan.neon including this package's phpstan.neon.dist and set paths
    • support --restore to revert from the latest backup

Setup script options and examples

  • Options:

    • --dry-run Show planned actions without modifying files
    • --no-backup Do not create backups before changing files
    • --paths="a,b,c" Comma-separated list of project paths to analyse (defaults: src,tests)
    • --restore[=DIR] Restore configs from the latest backup or from DIR if provided
  • Examples:

    • Default setup (with backup): vendor/bin/code-style-setup
    • Setup for custom paths: vendor/bin/code-style-setup --paths="src,modules,tests"
    • Dry run preview: vendor/bin/code-style-setup --dry-run
    • Restore from latest backup: vendor/bin/code-style-setup --restore
    • Restore from a specific backup directory: vendor/bin/code-style-setup --restore=.code-style-backups/20250101-120000

Run

  • Check coding style: composer cs:check
  • Auto-fix coding style: composer cs:fix
  • Static analysis: composer stan
  • Coverage (when running PHPUnit):
    • Text summary in console
    • Clover XML: build/logs/clover.xml
    • HTML report: build/coverage/

Notes

  • This package ships with reference configs:
    • .php-cs-fixer.dist.php — the default ruleset
    • phpstan.neon.dist — the default PHPStan config (level 9) including AdachSoft custom rule
  • When importing .php-cs-fixer.dist.php from vendor, always override the Finder to point to your project's root.

Versioning

  • No version field in composer.json. Versioning is managed exclusively via Git tags.

License

  • MIT (see LICENSE)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-04