diff --git a/CHANGELOG.md b/CHANGELOG.md index 3346430f..34ee795f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ For a full diff see [`1.2.0...main`][1.2.0...main]. ## Added - Added `Header::createWithoutReferenceToLicenseFile()` ([#534]), by [@localheinz] +- Added `None` ([#535]), by [@localheinz] ## Changed diff --git a/README.md b/README.md index ef84ab55..43e6ac59 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,22 @@ With [`friendsofphp/php-cs-fixer`](https://github.com/FriendsOfPHP/PHP-CS-Fixer) - save the license to a file, e.g. `LICENSE` or `LICENSE.md` - specify a file-level header using the `header_comment` fixer that will be replaced in PHP files -Here's an example of a `.php-cs-fixer.php` file: +Here's an example of a `.php-cs-fixer.php` file for an open-source project using the [`MIT`](src/Type/MIT.php) license type: ```php in(__DIR__); + +return Config::create() + ->setFinder($finder) + ->setRules([ + 'header_comment' => [ + 'comment_type' => 'PHPDoc', + 'header' => $license->header(), + 'location' => 'after_declare_strict', + 'separate' => 'both', + ], + ]); +``` + ### GitHub Actions When using [GitHub Actions](https://github.com/features/actions), you can set up a scheduled workflow that opens a pull request to the license year automatically on January 1st: @@ -144,6 +194,7 @@ Note that pull requests opened or commits pushed by GitHub Actions will not trig The following license types are currently available: - [`Ergebnis\License\Type\MIT`](src/Type/MIT.php) +- [`Ergebnis\License\Type\None`](src/Type/None.php) :bulb: Need a different license type? Feel free to open a pull request! diff --git a/src/Type/None.php b/src/Type/None.php new file mode 100644 index 00000000..4b9adbb9 --- /dev/null +++ b/src/Type/None.php @@ -0,0 +1,59 @@ +header = $header; + } + + public static function text( + Period $period, + Holder $holder, + Url $url + ): self { + return new self( + Template::fromFile(__DIR__ . '/../../resource/header/without-reference-to-license-file.txt'), + $period, + $holder, + $url, + ); + } + + public function header(): string + { + return $this->header->toString(); + } +} diff --git a/test/Unit/Type/NoneTest.php b/test/Unit/Type/NoneTest.php new file mode 100644 index 00000000..375e9967 --- /dev/null +++ b/test/Unit/Type/NoneTest.php @@ -0,0 +1,66 @@ +year()), + new \DateTimeZone($faker->timezone()), + ); + $holder = Holder::fromString($faker->name()); + $url = Url::fromString($faker->url()); + + $license = Type\None::text( + $range, + $holder, + $url, + ); + + $expected = <<toString()} {$holder->toString()} + +@see {$url->toString()} + +TXT; + + self::assertSame($expected, $license->header()); + } +}