AuthorPostUrl.php
1 day ago
CommentCount.php
1 day ago
FirstPost.php
1 day ago
FullName.php
1 day ago
HasRichEditing.php
1 day ago
LastPost.php
1 day ago
Meta.php
1 day ago
PostCount.php
1 day ago
PostCountOriginal.php
1 day ago
Property.php
1 day ago
Roles.php
1 day ago
ShowToolbar.php
1 day ago
TranslatedRoles.php
1 day ago
UserFilteredPostLink.php
1 day ago
UserLink.php
1 day ago
UserName.php
1 day ago
FullName.php
33 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Formatter\User; |
| 6 | |
| 7 | use AC\Exception\ValueNotFoundException; |
| 8 | use AC\Formatter; |
| 9 | use AC\Type\Value; |
| 10 | |
| 11 | class FullName implements Formatter |
| 12 | { |
| 13 | public function format(Value $value): Value |
| 14 | { |
| 15 | $user = get_userdata($value->get_id()); |
| 16 | |
| 17 | if (! $user) { |
| 18 | throw ValueNotFoundException::from_id($value->get_id()); |
| 19 | } |
| 20 | |
| 21 | $full_name = trim($user->first_name . ' ' . $user->last_name); |
| 22 | |
| 23 | if (! $full_name) { |
| 24 | throw ValueNotFoundException::from_id($value->get_id()); |
| 25 | } |
| 26 | |
| 27 | return $value->with_value( |
| 28 | $full_name |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | } |
| 33 |