定制 konradmichalik/php-doc-block-header-fixer 二次开发

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

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

konradmichalik/php-doc-block-header-fixer

最新稳定版本:0.3.3

Composer 安装命令:

composer require konradmichalik/php-doc-block-header-fixer

包简介

This package contains a PHP-CS-Fixer rule to automatically fix the class header regarding PHP DocBlocks.

README 文档

README

Php DocBlock Header Fixer

Coverage CGL Tests Supported PHP Versions

This packages contains a PHP-CS-Fixer rule to automatically fix the header regarding PHP DocBlocks for classes, interfaces, traits and enums.

Before:

<?php class MyClass { public function myMethod() { // ... } } interface MyInterface {} trait MyTrait {} enum MyEnum {}

After:

<?php /**  * MyClass.  *  * @author Your Name <your@email.org>  * @license GPL-3.0-or-later  */ class MyClass { // ... }

???? Installation

Packagist Packagist Downloads

composer require --dev konradmichalik/php-doc-block-header-fixer

⚡ Usage

Add the PHP-CS-Fixer rule in your .php-cs-fixer.php file:

Note

This fixer is compatible with standard PHP-CS-Fixer rules. It avoids adding annotations that conflict with rules like phpdoc_no_package and follows spacing conventions compatible with phpdoc_separation.

<?php // ... return (new PhpCsFixer\Config()) // ... ->registerCustomFixers([ new KonradMichalik\PhpDocBlockHeaderFixer\Rules\DocBlockHeaderFixer() ]) ->setRules([ 'KonradMichalik/docblock_header_comment' => [ 'annotations' => [ 'author' => 'Konrad Michalik <hej@konradmichalik.dev>', 'license' => 'GPL-3.0-or-later', ], 'preserve_existing' => true, 'separate' => 'none', 'add_structure_name' => true, ], ]) ;

Alternatively, you can use a object-oriented configuration:

<?php // ... return (new PhpCsFixer\Config()) // ... ->registerCustomFixers([ new KonradMichalik\PhpDocBlockHeaderFixer\Rules\DocBlockHeaderFixer() ]) ->setRules([ KonradMichalik\PhpDocBlockHeaderFixer\Generators\DocBlockHeader::create( [ 'author' => 'Konrad Michalik <hej@konradmichalik.dev>', 'license' => 'GPL-3.0-or-later', ], preserveExisting: true, separate: \KonradMichalik\PhpDocBlockHeaderFixer\Enum\Separate::None, addStructureName: true )->__toArray() ]) ;

Or even simpler, automatically read all authors and license from your composer.json:

<?php // ... return (new PhpCsFixer\Config()) // ... ->registerCustomFixers([ new KonradMichalik\PhpDocBlockHeaderFixer\Rules\DocBlockHeaderFixer() ]) ->setRules([ KonradMichalik\PhpDocBlockHeaderFixer\Generators\DocBlockHeader::fromComposer()->__toArray() ]) ;

⚙️ Configuration

  • annotations (array): DocBlock annotations to add to classes
  • preserve_existing (boolean, default: true): Keep existing DocBlock annotations
  • separate (string, default: 'none'): Add blank lines ('top', 'bottom', 'both', 'none')
  • add_structure_name (boolean, default: false): Add class name as first line in DocBlock
  • ensure_spacing (boolean, default: true): Ensure proper spacing after DocBlocks to prevent conflicts with PHP-CS-Fixer rules

????‍???? Contributing

Please have a look at CONTRIBUTING.md.

⭐ License

This project is licensed under GNU General Public License 3.0 (or later).

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固