Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Framework/Features/Blogging/Models/PostAuthor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/Features/XmlGenerators/RssFeedGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/MarkdownPostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 7 additions & 0 deletions tests/Unit/PostAuthorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading