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
4 changes: 3 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ This serves two purposes:

### Changed
- Updated the `Serializable` trait to provide a default automatic `toArray` method in https://github.com/hydephp/develop/pull/1791
- Updated the `PostAuthor` class's `name` property to fall back to the `username` property if the `name` property is not set in https://github.com/hydephp/develop/pull/1794
- Removed the nullable type hint from the `PostAuthor` class's `name` property as it is now always set in https://github.com/hydephp/develop/pull/1794

### Deprecated
- for soon-to-be removed features.
- The `PostAuthor::getName()` method is now deprecated and will be removed in v2. (use `$author->name` instead) in https://github.com/hydephp/develop/pull/1794

### Removed
- for now removed features.
Expand Down
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 packages/framework/tests/Feature/MarkdownPostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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 packages/framework/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