Skip to content

Commit 80d23b7

Browse files
authored
Merge pull request #675 from hydephp/prepare-post-author-changes
Update the post author class to prepare for the v2 overhaul
2 parents a4dca7b + 3946c11 commit 80d23b7

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

src/Framework/Features/Blogging/Models/PostAuthor.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Hyde\Facades\Author;
99
use Hyde\Facades\Config;
1010
use Illuminate\Support\Collection;
11+
use JetBrains\PhpStorm\Deprecated;
1112

1213
use function strtolower;
1314
use function is_string;
@@ -26,7 +27,7 @@ class PostAuthor implements Stringable
2627
/**
2728
* The display name of the author.
2829
*/
29-
public readonly ?string $name;
30+
public readonly string $name;
3031

3132
/**
3233
* The author's website URL.
@@ -48,7 +49,7 @@ class PostAuthor implements Stringable
4849
public function __construct(string $username, ?string $name = null, ?string $website = null)
4950
{
5051
$this->username = $username;
51-
$this->name = $name;
52+
$this->name = $name ?? $this->username;
5253
$this->website = $website;
5354
}
5455

@@ -82,12 +83,16 @@ public static function all(): Collection
8283

8384
public function __toString(): string
8485
{
85-
return $this->getName();
86+
return $this->name;
8687
}
8788

89+
/**
90+
* @deprecated This is not needed as the name property can be accessed directly.
91+
*/
92+
#[Deprecated(reason: 'Use the name property instead.', replacement: '%class%->name')]
8893
public function getName(): string
8994
{
90-
return $this->name ?? $this->username;
95+
return $this->name;
9196
}
9297

9398
/** @param array{username?: string, name?: string, website?: string} $data */

src/Framework/Features/XmlGenerators/RssFeedGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected function addDynamicItemData(SimpleXMLElement $item, MarkdownPost $post
6969
}
7070

7171
if (isset($post->author)) {
72-
$item->addChild('dc:creator', $post->author->getName(), 'http://purl.org/dc/elements/1.1/');
72+
$item->addChild('dc:creator', $post->author->name, 'http://purl.org/dc/elements/1.1/');
7373
}
7474

7575
if (isset($post->category)) {

tests/Feature/MarkdownPostTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testConstructorCanCreateANewAuthorInstanceFromUsernameString()
2929

3030
$this->assertInstanceOf(PostAuthor::class, $post->author);
3131
$this->assertSame('John Doe', $post->author->username);
32-
$this->assertNull($post->author->name);
32+
$this->assertSame('John Doe', $post->author->name);
3333
$this->assertNull($post->author->website);
3434
}
3535

tests/Unit/PostAuthorTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ public function testGetNameHelperReturnsUsernameIfNameIsNotSet()
134134
$this->assertEquals('username', $author->getName());
135135
}
136136

137+
public function testNameIsSetToUsernameIfNameIsNotSet()
138+
{
139+
$author = new PostAuthor('username');
140+
141+
$this->assertEquals('username', $author->name);
142+
}
143+
137144
public function testToStringHelperReturnsTheName()
138145
{
139146
$author = new PostAuthor('username', 'John Doe');

0 commit comments

Comments
 (0)