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.2.0
- phpstan/phpstan: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^11.0 || ^12.0 || ^13.0
- rector/rector: ^2.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- 0.4.0
- 0.3.5
- 0.3.4
- 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-docs/add-agents-md-source
- dev-feat/annotation-append-strategy
- dev-fix/opt-in-stale-structure-name
- dev-feat/align-docblockheader-with-fixer
- dev-fix/respect-indentation-and-line-ending
- dev-fix/keep-single-line-docblock-description
- dev-refactor/add-toarray-method
- dev-fix/converge-separator-whitespace
- dev-fix/validate-annotations-option
- dev-fix/visit-every-structure-in-one-run
- dev-chore/bump-reusable-workflows-0.1.0
- dev-chore/pin-reusable-workflows-0.0.1
- dev-docs/add-project-icon
This package is auto-updated.
Last update: 2026-10-02 10:42:04 UTC
README
Php DocBlock Header Fixer
PHP-CS-Fixer ships rules for DocBlock content and spacing, but none of them add or enforce header annotations such as @author and @license before a class, interface, trait or enum. Keeping those in sync by hand means every renamed class or licence change turns into a manual find-and-replace across the codebase. This package adds a configurable PHP-CS-Fixer rule that generates and enforces the annotations you configure, while leaving the rest of an existing DocBlock, descriptions, other tags, ordering untouched.
✨ Features
- Configurable annotations: add any tag (
@author,@license,@template,@phpstan-type, …), each enforced or appended independently - Composer autodiscovery:
fromComposer()reads authors and licence straight fromcomposer.json, so the header never drifts from the package metadata - Preserves existing DocBlocks: descriptions, other tags and ordering survive; only the configured annotations are enforced
- Structure name summaries: optionally prepend the class, interface, trait or enum name as the DocBlock's first line, with stale-name replacement on rename
- PHP-CS-Fixer compatible: avoids conflicts with
phpdoc_no_package,phpdoc_separationandno_blank_lines_after_phpdoc
🔥 Installation
Requirements
- PHP 8.2, 8.3, 8.4 or 8.5
ext-tokenizer(bundled with PHP by default)friendsofphp/php-cs-fixer^3.14 (installed automatically as a dependency)
Composer
composer require --dev konradmichalik/php-doc-block-header-fixer
🚀 Quick start
Register the fixer and read authors and licence straight from your composer.json:
<?php // ... return (new PhpCsFixer\Config()) // ... ->registerCustomFixers([ new KonradMichalik\PhpDocBlockHeaderFixer\Rules\DocBlockHeaderFixer(), ]) ->setRules([ KonradMichalik\PhpDocBlockHeaderFixer\Generators\DocBlockHeader::fromComposer(addStructureName: true)->toArray(), ]) ;
Running php-cs-fixer fix now turns
<?php class MyClass { public function myMethod(): void {} }
into
<?php /** * MyClass. * * @author Jane Doe <jane@example.com> * @license MIT */ class MyClass { public function myMethod(): void {} }
The same happens for interfaces, traits and enums. See Usage for the plain-array and object-oriented alternatives to fromComposer().
📚 Documentation
| Topic | What's inside |
|---|---|
| Usage | Registering the fixer: plain array, object-oriented builder, and fromComposer() autodiscovery |
| Configuration | Every option with its type, default and effect |
🧑💻 Contributing
Please have a look at CONTRIBUTING.md.
⭐ License
This project is licensed under GNU General Public License 3.0 (or later).