konradmichalik / php-doc-block-header-fixer
This package contains a PHP-CS-Fixer rule to automatically fix the class header regarding PHP DocBlocks.
Package info
github.com/konradmichalik/php-doc-block-header-fixer
pkg:composer/konradmichalik/php-doc-block-header-fixer
Requires
- php: ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0
- ext-tokenizer: *
- friendsofphp/php-cs-fixer: ^3.14
Requires (Dev)
- armin/editorconfig-cli: ^2.0
- ergebnis/composer-normalize: ^2.44
- konradmichalik/php-cs-fixer-preset: ^0.1.0
- phpstan/phpstan: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^11.0 || ^12.0
- rector/rector: ^2.2
- dev-main
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.0
- dev-renovate/phpstan-packages
- dev-renovate/lock-file-maintenance
- dev-renovate/phpunit-phpunit-13.x
- dev-renovate/friendsofphp-php-cs-fixer-3.x-lockfile
- dev-change-github-username
- dev-attribute-fix
- dev-update-dependencies
- dev-min-php-8.2
- dev-readonly-fix
This package is auto-updated.
Last update: 2026-03-17 16:50:49 UTC
README
Php DocBlock Header Fixer
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
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 classespreserve_existing(boolean, default: true): Keep existing DocBlock annotationsseparate(string, default: 'none'): Add blank lines ('top', 'bottom', 'both', 'none')add_structure_name(boolean, default: false): Add class name as first line in DocBlockensure_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).