Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hydephp/develop into 2.x-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jul 6, 2024
2 parents d69fa97 + cc57e00 commit b486ef3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
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

0 comments on commit b486ef3

Please sign in to comment.