From 3d6c1d784f94bf29b5a66fb2a747222e5cddc19d Mon Sep 17 00:00:00 2001 From: Felix Jahn Date: Fri, 17 Nov 2023 14:49:50 +0100 Subject: [PATCH] Enhancement: Add `BSD-3-Clause` as usable License --- CHANGELOG.md | 3 + README.md | 1 + psalm-baseline.xml | 8 + resource/license/BSD3Clause.md | 19 +++ resource/license/BSD3Clause.txt | 19 +++ src/Type/BSD3Clause.php | 96 ++++++++++++ test/Unit/Type/BSD3ClauseTest.php | 239 ++++++++++++++++++++++++++++++ 7 files changed, 385 insertions(+) create mode 100644 resource/license/BSD3Clause.md create mode 100644 resource/license/BSD3Clause.txt create mode 100644 src/Type/BSD3Clause.php create mode 100644 test/Unit/Type/BSD3ClauseTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 484a9c9b..b13356c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ For a full diff see [`2.2.0...main`][2.2.0...main]. ## Added - Added support for PHP 8.3 ([#734]), by [@localheinz] +- Added `BSD3Clause` ([#740]), by [@oruborus] ## [`2.2.0`][2.2.0] @@ -121,5 +122,7 @@ For a full diff see [`675601b...0.1.0`][675601b...0.1.0]. [#550]: https://github.com/ergebnis/license/pull/550 [#644]: https://github.com/ergebnis/license/pull/644 [#734]: https://github.com/ergebnis/license/pull/734 +[#740]: https://github.com/ergebnis/license/pull/740 [@localheinz]: https://github.com/localheinz +[@oruborus]: https://github.com/oruborus diff --git a/README.md b/README.md index ea39fdf1..23d6fd35 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,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/BSD3Clause.php) - [`Ergebnis\License\Type\MIT`](src/Type/MIT.php) - [`Ergebnis\License\Type\None`](src/Type/None.php) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 141a6404..6aec49e1 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -55,6 +55,14 @@ provideReplacementsWithInvalidValues + + + timezone()]]> + timezone()]]> + timezone()]]> + timezone()]]> + + timezone()]]> diff --git a/resource/license/BSD3Clause.md b/resource/license/BSD3Clause.md new file mode 100644 index 00000000..f8d22a6e --- /dev/null +++ b/resource/license/BSD3Clause.md @@ -0,0 +1,19 @@ +# BSD 3-Clause "New" or "Revised" License + +Copyright (c) . + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials + provided with the distribution. + + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS **AS IS** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/resource/license/BSD3Clause.txt b/resource/license/BSD3Clause.txt new file mode 100644 index 00000000..6a9e8f98 --- /dev/null +++ b/resource/license/BSD3Clause.txt @@ -0,0 +1,19 @@ +BSD 3-Clause "New" or "Revised" License + +Copyright (c) . + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials + provided with the distribution. + + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/Type/BSD3Clause.php b/src/Type/BSD3Clause.php new file mode 100644 index 00000000..991458e1 --- /dev/null +++ b/src/Type/BSD3Clause.php @@ -0,0 +1,96 @@ +file = $file; + $this->header = $header; + } + + public static function markdown( + string $name, + Period $period, + Holder $holder, + Url $url, + ): self { + return new self( + $name, + Template::fromFile(__DIR__ . '/../../resource/license/BSD3Clause.md'), + Template::fromFile(__DIR__ . '/../../resource/header/with-reference-to-license-file.txt'), + $period, + $holder, + $url, + ); + } + + public static function text( + string $name, + Period $period, + Holder $holder, + Url $url, + ): self { + return new self( + $name, + Template::fromFile(__DIR__ . '/../../resource/license/BSD3Clause.txt'), + Template::fromFile(__DIR__ . '/../../resource/header/with-reference-to-license-file.txt'), + $period, + $holder, + $url, + ); + } + + public function save(): void + { + $this->file->save(); + } + + public function header(): string + { + return $this->header->toString(); + } +} diff --git a/test/Unit/Type/BSD3ClauseTest.php b/test/Unit/Type/BSD3ClauseTest.php new file mode 100644 index 00000000..62a52eba --- /dev/null +++ b/test/Unit/Type/BSD3ClauseTest.php @@ -0,0 +1,239 @@ +mkdir(self::temporaryDirectory()); + } + + protected function tearDown(): void + { + $filesystem = new Filesystem\Filesystem(); + + $filesystem->remove(self::temporaryDirectory()); + } + + public function testHeaderReturnsHeaderForMarkdownLicense(): void + { + $faker = self::faker(); + + $baseName = \sprintf( + '%s.txt', + $faker->slug(), + ); + $name = \sprintf( + '%s/%s', + self::temporaryDirectory(), + $baseName, + ); + $range = Range::since( + Year::fromString($faker->year()), + new \DateTimeZone($faker->timezone()), + ); + $holder = Holder::fromString($faker->name()); + $url = Url::fromString($faker->url()); + + $license = Type\BSD3Clause::markdown( + $name, + $range, + $holder, + $url, + ); + + $expected = <<toString()} {$holder->toString()} + +For the full copyright and license information, please view +the {$baseName} file that was distributed with this source code. + +@see {$url->toString()} + +TXT; + + self::assertSame($expected, $license->header()); + } + + public function testHeaderReturnsHeaderForTextLicense(): void + { + $faker = self::faker(); + + $name = \sprintf( + '%s.txt', + $faker->slug(), + ); + $baseName = \sprintf( + '%s/%s', + self::temporaryDirectory(), + $name, + ); + $range = Range::since( + Year::fromString($faker->year()), + new \DateTimeZone($faker->timezone()), + ); + $holder = Holder::fromString($faker->name()); + $url = Url::fromString($faker->url()); + + $license = Type\BSD3Clause::text( + $baseName, + $range, + $holder, + $url, + ); + + $expected = <<toString()} {$holder->toString()} + +For the full copyright and license information, please view +the {$name} file that was distributed with this source code. + +@see {$url->toString()} + +TXT; + + self::assertSame($expected, $license->header()); + } + + public function testSaveSavesMarkdownToFileForMarkdownLicense(): void + { + $faker = self::faker(); + + $name = \sprintf( + '%s/%s.md', + self::temporaryDirectory(), + $faker->slug(), + ); + $range = Range::since( + Year::fromString($faker->year()), + new \DateTimeZone($faker->timezone()), + ); + $holder = Holder::fromString($faker->name()); + $url = Url::fromString($faker->url()); + + $license = Type\BSD3Clause::markdown( + $name, + $range, + $holder, + $url, + ); + + $license->save(); + + self::assertFileExists($name); + + $expected = <<toString()} {$holder->toString()}. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials + provided with the distribution. + + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS **AS IS** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +TXT; + + self::assertSame($expected, \file_get_contents($name)); + } + + public function testSaveSavesTextToFileForTextLicense(): void + { + $faker = self::faker(); + + $name = \sprintf( + '%s/%s.txt', + self::temporaryDirectory(), + $faker->slug(), + ); + $range = Range::since( + Year::fromString($faker->year()), + new \DateTimeZone($faker->timezone()), + ); + $holder = Holder::fromString($faker->name()); + $url = Url::fromString($faker->url()); + + $license = Type\BSD3Clause::text( + $name, + $range, + $holder, + $url, + ); + + $license->save(); + + self::assertFileExists($name); + + $expected = <<toString()} {$holder->toString()}. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials + provided with the distribution. + + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +TXT; + + self::assertSame($expected, \file_get_contents($name)); + } +}