https://github.com/jackd248/php-doc-block-header-fixer
📝 PHP CS Fixer rule for fix the class header regarding PHP DocBlocks
https://github.com/jackd248/php-doc-block-header-fixer
php-cs-fixer php-cs-fixer-custom-fixers
Last synced: 8 months ago
JSON representation
📝 PHP CS Fixer rule for fix the class header regarding PHP DocBlocks
- Host: GitHub
- URL: https://github.com/jackd248/php-doc-block-header-fixer
- Owner: jackd248
- License: gpl-3.0
- Created: 2025-08-07T11:37:19.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-10-23T12:21:58.000Z (8 months ago)
- Last Synced: 2025-10-23T13:35:29.828Z (8 months ago)
- Topics: php-cs-fixer, php-cs-fixer-custom-fixers
- Language: PHP
- Homepage:
- Size: 186 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# Php DocBlock Header Fixer
[](https://coveralls.io/github/jackd248/php-doc-block-header-fixer)
[](https://github.com/jackd248/php-doc-block-header-fixer/actions/workflows/cgl.yml)
[](https://github.com/jackd248/php-doc-block-header-fixer/actions/workflows/tests.yml)
[](https://packagist.org/packages/konradmichalik/php-doc-block-header-fixer)
This packages contains a [PHP-CS-Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) rule to automatically fix the header regarding PHP DocBlocks for classes, interfaces, traits and enums.
**Before:**
```php
* @license GPL-3.0-or-later
*/
class MyClass
{
// ...
}
```
## 🔥 Installation
[](https://packagist.org/packages/konradmichalik/php-doc-block-header-fixer)
[](https://packagist.org/packages/konradmichalik/php-doc-block-header-fixer)
```bash
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
registerCustomFixers([
new KonradMichalik\PhpDocBlockHeaderFixer\Rules\DocBlockHeaderFixer()
])
->setRules([
'KonradMichalik/docblock_header_comment' => [
'annotations' => [
'author' => 'Konrad Michalik ',
'license' => 'GPL-3.0-or-later',
],
'preserve_existing' => true,
'separate' => 'none',
'add_structure_name' => true,
],
])
;
```
Alternatively, you can use a object-oriented configuration:
```php
registerCustomFixers([
new KonradMichalik\PhpDocBlockHeaderFixer\Rules\DocBlockHeaderFixer()
])
->setRules([
KonradMichalik\PhpDocBlockHeaderFixer\Generators\DocBlockHeader::create(
[
'author' => 'Konrad Michalik ',
'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
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`](CONTRIBUTING.md).
## ⭐ License
This project is licensed under [GNU General Public License 3.0 (or later)](LICENSE.md).