Skip to content

Commit 6950ea2

Browse files
authored
Merge pull request #10 from jackd248/from-composer
feat: add ComposerService for handling composer.json data
2 parents 585a105 + d8a5356 commit 6950ea2

File tree

14 files changed

+881
-279
lines changed

14 files changed

+881
-279
lines changed

.php-cs-fixer.php

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,32 @@
33
declare(strict_types=1);
44

55
/*
6-
* This file is part of the Composer package "php-doc-block-header-fixer".
6+
* This file is part of the "php-doc-block-header-fixer" Composer package.
77
*
8-
* Copyright (C) 2025 Konrad Michalik <hej@konradmichalik.dev>
8+
* (c) Konrad Michalik <hej@konradmichalik.dev>
99
*
10-
* This program is free software: you can redistribute it and/or modify
11-
* it under the terms of the GNU General Public License as published by
12-
* the Free Software Foundation, either version 3 of the License, or
13-
* (at your option) any later version.
14-
*
15-
* This program is distributed in the hope that it will be useful,
16-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18-
* GNU General Public License for more details.
19-
*
20-
* You should have received a copy of the GNU General Public License
21-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
2212
*/
2313

24-
use EliasHaeussler\PhpCsFixerConfig\Config;
25-
use EliasHaeussler\PhpCsFixerConfig\Package;
26-
use EliasHaeussler\PhpCsFixerConfig\Rules;
27-
use Symfony\Component\Finder;
28-
29-
$header = Rules\Header::create(
30-
'php-doc-block-header-fixer',
31-
Package\Type::ComposerPackage,
32-
Package\Author::create('Konrad Michalik', 'hej@konradmichalik.dev'),
33-
Package\CopyrightRange::from(2025),
34-
Package\License::GPL3OrLater,
35-
);
14+
use KonradMichalik\PhpCsFixerPreset\Config;
15+
use KonradMichalik\PhpCsFixerPreset\Rules\Header;
16+
use KonradMichalik\PhpCsFixerPreset\Rules\Set\Set;
17+
use KonradMichalik\PhpDocBlockHeaderFixer\Generators\DocBlockHeader;
18+
use KonradMichalik\PhpDocBlockHeaderFixer\Rules\DocBlockHeaderFixer;
19+
use Symfony\Component\Finder\Finder;
3620

3721
return Config::create()
38-
->withRule($header)
39-
// ->withRule(
40-
// RuleSet::fromArray(
41-
// DocBlockHeader::create(
42-
// [
43-
// 'author' => 'Konrad Michalik <hej@konradmichalik.dev>',
44-
// 'license' => 'GPL-3.0-or-later',
45-
// 'package' => 'PhpDocBlockHeaderFixer',
46-
// ]
47-
// )->__toArray()
48-
// )
49-
// )
50-
// ->registerCustomFixers([new KonradMichalik\PhpDocBlockHeaderFixer\Rules\DocBlockHeaderFixer()]) // Temporarily disabled
51-
->withFinder(static fn (Finder\Finder $finder) => $finder
52-
->in(__DIR__)
53-
->exclude('vendor'),
22+
->registerCustomFixers([
23+
new DocBlockHeaderFixer(),
24+
])
25+
->withRule(
26+
Header::fromComposer(),
27+
)
28+
->withRule(
29+
Set::fromArray(
30+
DocBlockHeader::fromComposer()->__toArray(),
31+
),
5432
)
33+
->withFinder(static fn (Finder $finder) => $finder->in(__DIR__))
5534
;

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@ return (new PhpCsFixer\Config())
110110
;
111111
```
112112

113+
Or even simpler, automatically read all authors and license from your `composer.json`:
114+
115+
```php
116+
<?php
117+
// ...
118+
return (new PhpCsFixer\Config())
119+
// ...
120+
->registerCustomFixers([
121+
new KonradMichalik\PhpDocBlockHeaderFixer\Rules\DocBlockHeaderFixer()
122+
])
123+
->setRules([
124+
KonradMichalik\PhpDocBlockHeaderFixer\Generators\DocBlockHeader::fromComposer()->__toArray()
125+
])
126+
;
127+
```
128+
113129
## ⚙️ Configuration
114130

115131
- `annotations` (array): DocBlock annotations to add to classes

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
},
2828
"require-dev": {
2929
"armin/editorconfig-cli": "^1.0 || ^2.0",
30-
"eliashaeussler/php-cs-fixer-config": "2.3.0",
3130
"eliashaeussler/rector-config": "^3.0",
3231
"ergebnis/composer-normalize": "^2.44",
32+
"konradmichalik/php-cs-fixer-preset": "^0.1.0",
3333
"phpstan/phpstan": "^2.0",
3434
"phpstan/phpstan-phpunit": "^2.0",
3535
"phpstan/phpstan-symfony": "^2.0",
@@ -40,6 +40,11 @@
4040
"KonradMichalik\\PhpDocBlockHeaderFixer\\": "src"
4141
}
4242
},
43+
"autoload-dev": {
44+
"psr-4": {
45+
"KonradMichalik\\PhpDocBlockHeaderFixer\\Tests\\": "tests/src"
46+
}
47+
},
4348
"config": {
4449
"allow-plugins": {
4550
"ergebnis/composer-normalize": true

composer.lock

Lines changed: 79 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rector.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,12 @@
33
declare(strict_types=1);
44

55
/*
6-
* This file is part of the Composer package "php-doc-block-header-fixer".
6+
* This file is part of the "php-doc-block-header-fixer" Composer package.
77
*
8-
* Copyright (C) 2025 Konrad Michalik <hej@konradmichalik.dev>
8+
* (c) Konrad Michalik <hej@konradmichalik.dev>
99
*
10-
* This program is free software: you can redistribute it and/or modify
11-
* it under the terms of the GNU General Public License as published by
12-
* the Free Software Foundation, either version 3 of the License, or
13-
* (at your option) any later version.
14-
*
15-
* This program is distributed in the hope that it will be useful,
16-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18-
* GNU General Public License for more details.
19-
*
20-
* You should have received a copy of the GNU General Public License
21-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
2212
*/
2313

2414
use EliasHaeussler\RectorConfig\Config\Config;

0 commit comments

Comments
 (0)