From 1f5b17be04df3da7634a88c6997eb6a39ec346b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Thu, 2 Jan 2020 19:05:38 +0100 Subject: [PATCH] Fix: Rename --- .php_cs | 4 +- .../{Author.php => Copyright/Holder.php} | 4 +- src/License/{ => Copyright}/Year.php | 2 +- .../Years.php} | 24 ++--- src/License/Header.php | 20 ++-- .../HolderTest.php} | 22 ++--- .../Unit/License/{ => Copyright}/YearTest.php | 6 +- test/Unit/License/Copyright/YearsTest.php | 92 +++++++++++++++++++ test/Unit/License/CopyrightYearsTest.php | 92 ------------------- test/Unit/License/HeaderTest.php | 32 +++---- test/Unit/License/UrlTest.php | 4 +- 11 files changed, 151 insertions(+), 151 deletions(-) rename src/License/{Author.php => Copyright/Holder.php} (92%) rename src/License/{ => Copyright}/Year.php (96%) rename src/License/{CopyrightYears.php => Copyright/Years.php} (65%) rename test/Unit/License/{AuthorTest.php => Copyright/HolderTest.php} (76%) rename test/Unit/License/{ => Copyright}/YearTest.php (94%) create mode 100644 test/Unit/License/Copyright/YearsTest.php delete mode 100644 test/Unit/License/CopyrightYearsTest.php diff --git a/.php_cs b/.php_cs index ee2d4138..32678dcf 100644 --- a/.php_cs +++ b/.php_cs @@ -14,8 +14,8 @@ declare(strict_types=1); use Ergebnis\PhpCsFixer\Config; $header = Config\License\Header::create( - Config\License\CopyrightYears::fromYear(Config\License\Year::fromString('2019')), - Config\License\Author::fromString('Andreas Möller'), + Config\License\Copyright\Years::fromYear(Config\License\Copyright\Year::fromString('2019')), + Config\License\Copyright\Holder::fromString('Andreas Möller'), Config\License\Notice::fromString( <<<'EOF' For the full copyright and license information, please view diff --git a/src/License/Author.php b/src/License/Copyright/Holder.php similarity index 92% rename from src/License/Author.php rename to src/License/Copyright/Holder.php index 4003d76d..b3091da8 100644 --- a/src/License/Author.php +++ b/src/License/Copyright/Holder.php @@ -11,12 +11,12 @@ * @see https://github.com/ergebnis/php-cs-fixer-config */ -namespace Ergebnis\PhpCsFixer\Config\License; +namespace Ergebnis\PhpCsFixer\Config\License\Copyright; /** * @internal */ -final class Author +final class Holder { private $value; diff --git a/src/License/Year.php b/src/License/Copyright/Year.php similarity index 96% rename from src/License/Year.php rename to src/License/Copyright/Year.php index f268f62d..9b4e3478 100644 --- a/src/License/Year.php +++ b/src/License/Copyright/Year.php @@ -11,7 +11,7 @@ * @see https://github.com/ergebnis/php-cs-fixer-config */ -namespace Ergebnis\PhpCsFixer\Config\License; +namespace Ergebnis\PhpCsFixer\Config\License\Copyright; /** * @internal diff --git a/src/License/CopyrightYears.php b/src/License/Copyright/Years.php similarity index 65% rename from src/License/CopyrightYears.php rename to src/License/Copyright/Years.php index ba47abbb..b7c388a6 100644 --- a/src/License/CopyrightYears.php +++ b/src/License/Copyright/Years.php @@ -11,12 +11,12 @@ * @see https://github.com/ergebnis/php-cs-fixer-config */ -namespace Ergebnis\PhpCsFixer\Config\License; +namespace Ergebnis\PhpCsFixer\Config\License\Copyright; /** * @internal */ -final class CopyrightYears +final class Years { private $value; @@ -26,31 +26,31 @@ private function __construct(string $value) } /** - * @param Year $startYear - * @param Year $endYear + * @param Year $start + * @param Year $end * * @throws \InvalidArgumentException * * @return self */ - public static function fromRange(Year $startYear, Year $endYear): self + public static function fromRange(Year $start, Year $end): self { - if ($startYear->greaterThan($endYear)) { + if ($start->greaterThan($end)) { throw new \InvalidArgumentException(\sprintf( 'Start year "%s" needs to be equal to or less than end year "%s".', - $startYear->toString(), - $endYear->toString() + $start->toString(), + $end->toString() )); } - if ($startYear->equals($endYear)) { - return self::fromYear($startYear); + if ($start->equals($end)) { + return self::fromYear($start); } return new self(\sprintf( '%s-%s', - $startYear->toString(), - $endYear->toString() + $start->toString(), + $end->toString() )); } diff --git a/src/License/Header.php b/src/License/Header.php index 99703be1..079ef2d9 100644 --- a/src/License/Header.php +++ b/src/License/Header.php @@ -18,27 +18,27 @@ */ final class Header { - private $copyrightYears; + private $years; - private $author; + private $holder; private $notice; private $url; - private function __construct(CopyrightYears $copyrightYears, Author $author, Notice $notice, Url $url) + private function __construct(Copyright\Years $years, Copyright\Holder $holder, Notice $notice, Url $url) { - $this->copyrightYears = $copyrightYears; - $this->author = $author; + $this->years = $years; + $this->holder = $holder; $this->notice = $notice; $this->url = $url; } - public static function create(CopyrightYears $copyrightYears, Author $author, Notice $notice, Url $url): self + public static function create(Copyright\Years $years, Copyright\Holder $holder, Notice $notice, Url $url): self { return new self( - $copyrightYears, - $author, + $years, + $holder, $notice, $url ); @@ -48,14 +48,14 @@ public function toString(): string { if ($this->notice->isEmpty()) { return <<copyrightYears->toString()} {$this->author->toString()} +Copyright (c) {$this->years->toString()} {$this->holder->toString()} @see {$this->url->toString()} EOF; } return <<copyrightYears->toString()} {$this->author->toString()} +Copyright (c) {$this->years->toString()} {$this->holder->toString()} {$this->notice->toString()} diff --git a/test/Unit/License/AuthorTest.php b/test/Unit/License/Copyright/HolderTest.php similarity index 76% rename from test/Unit/License/AuthorTest.php rename to test/Unit/License/Copyright/HolderTest.php index b9d216c2..a278d1f9 100644 --- a/test/Unit/License/AuthorTest.php +++ b/test/Unit/License/Copyright/HolderTest.php @@ -11,18 +11,18 @@ * @see https://github.com/ergebnis/php-cs-fixer-config */ -namespace Ergebnis\PhpCsFixer\Config\Test\Unit\License; +namespace Ergebnis\PhpCsFixer\Config\Test\Unit\License\Copyright; -use Ergebnis\PhpCsFixer\Config\License\Author; +use Ergebnis\PhpCsFixer\Config\License\Copyright\Holder; use Ergebnis\Test\Util\Helper; use PHPUnit\Framework; /** * @internal * - * @covers \Ergebnis\PhpCsFixer\Config\License\Author + * @covers \Ergebnis\PhpCsFixer\Config\License\Copyright\Holder */ -final class AuthorTest extends Framework\TestCase +final class HolderTest extends Framework\TestCase { use Helper; @@ -36,7 +36,7 @@ public function testFromStringRejectsInvalidValue(string $value): void $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Value cannot be blank or empty.'); - Author::fromString($value); + Holder::fromString($value); } public function provideInvalidValue(): \Generator @@ -58,11 +58,11 @@ public function provideInvalidValue(): \Generator * * @param string $value */ - public function testFromStringReturnsAuthor(string $value): void + public function testFromStringReturnsHolder(string $value): void { - $author = Author::fromString($value); + $holder = Holder::fromString($value); - self::assertSame($value, $author->toString()); + self::assertSame($value, $holder->toString()); } public function provideValidValue(): \Generator @@ -79,11 +79,11 @@ public function provideValidValue(): \Generator * * @param string $value */ - public function testFromStringReturnsAuthorWithTrimmedValue(string $value): void + public function testFromStringReturnsHolderWithTrimmedValue(string $value): void { - $author = Author::fromString($value); + $holder = Holder::fromString($value); - self::assertSame(\trim($value), $author->toString()); + self::assertSame(\trim($value), $holder->toString()); } public function provideUntrimmedValue(): \Generator diff --git a/test/Unit/License/YearTest.php b/test/Unit/License/Copyright/YearTest.php similarity index 94% rename from test/Unit/License/YearTest.php rename to test/Unit/License/Copyright/YearTest.php index 30e07b9f..ec5347d5 100644 --- a/test/Unit/License/YearTest.php +++ b/test/Unit/License/Copyright/YearTest.php @@ -11,16 +11,16 @@ * @see https://github.com/ergebnis/php-cs-fixer-config */ -namespace Ergebnis\PhpCsFixer\Config\Test\Unit\License; +namespace Ergebnis\PhpCsFixer\Config\Test\Unit\License\Copyright; -use Ergebnis\PhpCsFixer\Config\License\Year; +use Ergebnis\PhpCsFixer\Config\License\Copyright\Year; use Ergebnis\Test\Util\Helper; use PHPUnit\Framework; /** * @internal * - * @covers \Ergebnis\PhpCsFixer\Config\License\Year + * @covers \Ergebnis\PhpCsFixer\Config\License\Copyright\Year */ final class YearTest extends Framework\TestCase { diff --git a/test/Unit/License/Copyright/YearsTest.php b/test/Unit/License/Copyright/YearsTest.php new file mode 100644 index 00000000..e5e0ace3 --- /dev/null +++ b/test/Unit/License/Copyright/YearsTest.php @@ -0,0 +1,92 @@ +expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage(\sprintf( + 'Start year "%s" needs to be equal to or less than end year "%s".', + $start->toString(), + $end->toString() + )); + + Years::fromRange( + $start, + $end + ); + } + + public function testFromRangeReturnsYearsWhenStartYearEqualsEndYear(): void + { + $start = Year::fromString('2020'); + $end = Year::fromString('2020'); + + $years = Years::fromRange( + $start, + $end + ); + + self::assertSame($start->toString(), $years->toString()); + } + + public function testFromRangeReturnsYearsWhenStartYearIsLessThanEndYear(): void + { + $start = Year::fromString('2019'); + $end = Year::fromString('2020'); + + $years = Years::fromRange( + $start, + $end + ); + + $expected = \sprintf( + '%s-%s', + $start->toString(), + $end->toString() + ); + + self::assertSame($expected, $years->toString()); + } + + public function testFromYearReturnsYears(): void + { + $year = Year::fromString('2019'); + + $years = Years::fromYear($year); + + self::assertSame($year->toString(), $years->toString()); + } +} diff --git a/test/Unit/License/CopyrightYearsTest.php b/test/Unit/License/CopyrightYearsTest.php deleted file mode 100644 index 47f4ea84..00000000 --- a/test/Unit/License/CopyrightYearsTest.php +++ /dev/null @@ -1,92 +0,0 @@ -expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage(\sprintf( - 'Start year "%s" needs to be equal to or less than end year "%s".', - $startYear->toString(), - $endYear->toString() - )); - - CopyrightYears::fromRange( - $startYear, - $endYear - ); - } - - public function testFromRangeReturnsCopyrightYearsWhenStartYearEqualsEndYear(): void - { - $startYear = Year::fromString('2020'); - $endYear = Year::fromString('2020'); - - $copyrightYears = CopyrightYears::fromRange( - $startYear, - $endYear - ); - - self::assertSame($startYear->toString(), $copyrightYears->toString()); - } - - public function testFromRangeReturnsCopyrightYearsWhenStartYearIsLessThanEndYear(): void - { - $startYear = Year::fromString('2019'); - $endYear = Year::fromString('2020'); - - $copyrightYears = CopyrightYears::fromRange( - $startYear, - $endYear - ); - - $expected = \sprintf( - '%s-%s', - $startYear->toString(), - $endYear->toString() - ); - - self::assertSame($expected, $copyrightYears->toString()); - } - - public function testFromYearReturnsCopyrightYears(): void - { - $year = Year::fromString('2019'); - - $copyrightYears = CopyrightYears::fromYear($year); - - self::assertSame($year->toString(), $copyrightYears->toString()); - } -} diff --git a/test/Unit/License/HeaderTest.php b/test/Unit/License/HeaderTest.php index 838f28b9..e507cff0 100644 --- a/test/Unit/License/HeaderTest.php +++ b/test/Unit/License/HeaderTest.php @@ -13,12 +13,12 @@ namespace Ergebnis\PhpCsFixer\Config\Test\Unit\License; -use Ergebnis\PhpCsFixer\Config\License\Author; -use Ergebnis\PhpCsFixer\Config\License\CopyrightYears; +use Ergebnis\PhpCsFixer\Config\License\Copyright\Holder; +use Ergebnis\PhpCsFixer\Config\License\Copyright\Year; +use Ergebnis\PhpCsFixer\Config\License\Copyright\Years; use Ergebnis\PhpCsFixer\Config\License\Header; use Ergebnis\PhpCsFixer\Config\License\Notice; use Ergebnis\PhpCsFixer\Config\License\Url; -use Ergebnis\PhpCsFixer\Config\License\Year; use Ergebnis\Test\Util\Helper; use PHPUnit\Framework; @@ -27,11 +27,11 @@ * * @covers \Ergebnis\PhpCsFixer\Config\License\Header * - * @uses \Ergebnis\PhpCsFixer\Config\License\Author - * @uses \Ergebnis\PhpCsFixer\Config\License\CopyrightYears + * @uses \Ergebnis\PhpCsFixer\Config\License\Copyright\Holder + * @uses \Ergebnis\PhpCsFixer\Config\License\Copyright\Year + * @uses \Ergebnis\PhpCsFixer\Config\License\Copyright\Years * @uses \Ergebnis\PhpCsFixer\Config\License\Notice * @uses \Ergebnis\PhpCsFixer\Config\License\Url - * @uses \Ergebnis\PhpCsFixer\Config\License\Year */ final class HeaderTest extends Framework\TestCase { @@ -41,24 +41,24 @@ public function testCreateReturnsHeaderWhenLicenseIsEmpty(): void { $faker = self::faker(); - $copyrightYears = CopyrightYears::fromRange( + $years = Years::fromRange( Year::fromString('2019'), Year::fromString(\date('2020')) ); - $author = Author::fromString($faker->name); + $holder = Holder::fromString($faker->name); $url = Url::fromString($faker->url); $header = Header::create( - $copyrightYears, - $author, + $years, + $holder, Notice::fromString(''), $url ); $expected = <<toString()} {$author->toString()} +Copyright (c) {$years->toString()} {$holder->toString()} @see {$url->toString()} EOF; @@ -70,12 +70,12 @@ public function testCreateReturnsHeaderWhenLicenseIsNotEmpty(): void { $faker = self::faker(); - $copyrightYears = CopyrightYears::fromRange( + $years = Years::fromRange( Year::fromString('2019'), Year::fromString(\date('2020')) ); - $author = Author::fromString($faker->name); + $holder = Holder::fromString($faker->name); $notice = Notice::fromString( <<<'EOF' @@ -87,14 +87,14 @@ public function testCreateReturnsHeaderWhenLicenseIsNotEmpty(): void $url = Url::fromString($faker->url); $header = Header::create( - $copyrightYears, - $author, + $years, + $holder, $notice, $url ); $expected = <<toString()} {$author->toString()} +Copyright (c) {$years->toString()} {$holder->toString()} {$notice->toString()} diff --git a/test/Unit/License/UrlTest.php b/test/Unit/License/UrlTest.php index 3b9eb11e..f0fa71ee 100644 --- a/test/Unit/License/UrlTest.php +++ b/test/Unit/License/UrlTest.php @@ -85,9 +85,9 @@ public function provideValidValue(): \Generator */ public function testFromStringReturnsUrlWithTrimmedValue(string $value): void { - $author = Url::fromString($value); + $url = Url::fromString($value); - self::assertSame(\trim($value), $author->toString()); + self::assertSame(\trim($value), $url->toString()); } public function provideUntrimmedValue(): \Generator