Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Author | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Hyde\Framework\Models; |
| 4 | |
| 5 | /** |
| 6 | * The Post Author Object Model. |
| 7 | */ |
| 8 | class Author |
| 9 | { |
| 10 | /** |
| 11 | * The username of the author. |
| 12 | * This is the key used to find authors in the config. |
| 13 | * |
| 14 | * @var string |
| 15 | */ |
| 16 | public string $username; |
| 17 | |
| 18 | /** |
| 19 | * The display name of the author. |
| 20 | * |
| 21 | * @var string|null |
| 22 | */ |
| 23 | public ?string $name = null; |
| 24 | |
| 25 | /** |
| 26 | * The author's website URI. |
| 27 | * |
| 28 | * Could for example, be a Twitter page, website, |
| 29 | * or a hyperlink to more posts by the author. |
| 30 | * |
| 31 | * @var string|null |
| 32 | */ |
| 33 | public ?string $website = null; |
| 34 | |
| 35 | /** |
| 36 | * Construct a new Author object. |
| 37 | * |
| 38 | * Parameters are supplied through an array to make it |
| 39 | * easy to load data from Markdown post front matter. |
| 40 | * |
| 41 | * @param string $username |
| 42 | * @param array|null $data |
| 43 | */ |
| 44 | public function __construct(string $username, ?array $data = []) |
| 45 | { |
| 46 | $this->username = $username; |
| 47 | if (isset($data['name'])) { |
| 48 | $this->name = $data['name']; |
| 49 | } |
| 50 | if (isset($data['website'])) { |
| 51 | $this->website = $data['website']; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Get the author's preferred name. |
| 57 | * |
| 58 | * @see \Tests\Unit\AuthorGetNameTest |
| 59 | * |
| 60 | * @return string |
| 61 | */ |
| 62 | public function getName(): string |
| 63 | { |
| 64 | return $this->name ?? $this->username; |
| 65 | } |
| 66 | } |