diff --git a/src/Framework/Features/Blogging/Models/PostAuthor.php b/src/Framework/Features/Blogging/Models/PostAuthor.php index ac6b850b..35236438 100644 --- a/src/Framework/Features/Blogging/Models/PostAuthor.php +++ b/src/Framework/Features/Blogging/Models/PostAuthor.php @@ -8,6 +8,7 @@ use Hyde\Facades\Author; use Hyde\Facades\Config; use Illuminate\Support\Collection; +use JetBrains\PhpStorm\Deprecated; use function strtolower; use function is_string; @@ -26,7 +27,7 @@ class PostAuthor implements Stringable /** * The display name of the author. */ - public readonly ?string $name; + public readonly string $name; /** * The author's website URL. @@ -48,7 +49,7 @@ class PostAuthor implements Stringable public function __construct(string $username, ?string $name = null, ?string $website = null) { $this->username = $username; - $this->name = $name; + $this->name = $name ?? $this->username; $this->website = $website; } @@ -82,12 +83,16 @@ public static function all(): Collection public function __toString(): string { - return $this->getName(); + return $this->name; } + /** + * @deprecated This is not needed as the name property can be accessed directly. + */ + #[Deprecated(reason: 'Use the name property instead.', replacement: '%class%->name')] public function getName(): string { - return $this->name ?? $this->username; + return $this->name; } /** @param array{username?: string, name?: string, website?: string} $data */ diff --git a/src/Framework/Features/XmlGenerators/RssFeedGenerator.php b/src/Framework/Features/XmlGenerators/RssFeedGenerator.php index 09ebc3db..b3abfab4 100644 --- a/src/Framework/Features/XmlGenerators/RssFeedGenerator.php +++ b/src/Framework/Features/XmlGenerators/RssFeedGenerator.php @@ -69,7 +69,7 @@ protected function addDynamicItemData(SimpleXMLElement $item, MarkdownPost $post } if (isset($post->author)) { - $item->addChild('dc:creator', $post->author->getName(), 'http://purl.org/dc/elements/1.1/'); + $item->addChild('dc:creator', $post->author->name, 'http://purl.org/dc/elements/1.1/'); } if (isset($post->category)) { diff --git a/tests/Feature/MarkdownPostTest.php b/tests/Feature/MarkdownPostTest.php index ef8c319d..f3f3b315 100644 --- a/tests/Feature/MarkdownPostTest.php +++ b/tests/Feature/MarkdownPostTest.php @@ -29,7 +29,7 @@ public function testConstructorCanCreateANewAuthorInstanceFromUsernameString() $this->assertInstanceOf(PostAuthor::class, $post->author); $this->assertSame('John Doe', $post->author->username); - $this->assertNull($post->author->name); + $this->assertSame('John Doe', $post->author->name); $this->assertNull($post->author->website); } diff --git a/tests/Unit/PostAuthorTest.php b/tests/Unit/PostAuthorTest.php index c6c98a9c..503c59f5 100644 --- a/tests/Unit/PostAuthorTest.php +++ b/tests/Unit/PostAuthorTest.php @@ -134,6 +134,13 @@ public function testGetNameHelperReturnsUsernameIfNameIsNotSet() $this->assertEquals('username', $author->getName()); } + public function testNameIsSetToUsernameIfNameIsNotSet() + { + $author = new PostAuthor('username'); + + $this->assertEquals('username', $author->name); + } + public function testToStringHelperReturnsTheName() { $author = new PostAuthor('username', 'John Doe');