Author.php
2 days ago
CommentLink.php
2 days ago
CommentObject.php
2 days ago
CommentText.php
2 days ago
Content.php
2 days ago
LinkableCommentDate.php
2 days ago
Meta.php
2 days ago
MetaDateAndAuthor.php
2 days ago
ParentId.php
2 days ago
Property.php
2 days ago
ReplyToLink.php
2 days ago
StatusLabel.php
2 days ago
UserId.php
2 days ago
ParentId.php
26 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Formatter\Comment; |
| 6 | |
| 7 | use AC\Exception\ValueNotFoundException; |
| 8 | use AC\Formatter; |
| 9 | use AC\Type\Value; |
| 10 | use WP_Comment; |
| 11 | |
| 12 | class ParentId implements Formatter |
| 13 | { |
| 14 | public function format(Value $value): Value |
| 15 | { |
| 16 | $comment = get_comment($value->get_id()); |
| 17 | |
| 18 | if (! $comment instanceof WP_Comment || ! $comment->comment_parent) { |
| 19 | throw ValueNotFoundException::from_id($value->get_id()); |
| 20 | } |
| 21 | |
| 22 | return new Value((int)$comment->comment_parent); |
| 23 | } |
| 24 | |
| 25 | } |
| 26 |