| @@ 28-64 (lines=37) @@ | ||
| 25 | use function array_map; |
|
| 26 | use function count; |
|
| 27 | ||
| 28 | final class PostCommentsResolver |
|
| 29 | { |
|
| 30 | /** |
|
| 31 | * @var CommentRepositoryInterface |
|
| 32 | */ |
|
| 33 | private $commentRepository; |
|
| 34 | ||
| 35 | public function __construct( |
|
| 36 | CommentRepositoryInterface $commentRepository |
|
| 37 | ) { |
|
| 38 | $this->commentRepository = $commentRepository; |
|
| 39 | } |
|
| 40 | ||
| 41 | public function getPostCommentsConnection(PostId $postId): Connection |
|
| 42 | { |
|
| 43 | try { |
|
| 44 | /** @var Collection $postCommentList */ |
|
| 45 | $postCommentList = $this->commentRepository->findAllByPostId($postId); |
|
| 46 | } catch (EmptyQueryResultException $e) { |
|
| 47 | return ConnectionBuilder::connectionFromArray([]); |
|
| 48 | } |
|
| 49 | ||
| 50 | $commentViewModelList = array_map( |
|
| 51 | function (Comment $comment) { |
|
| 52 | return CommentViewModel::constructFromEntity($comment); |
|
| 53 | }, |
|
| 54 | $postCommentList->toArray() |
|
| 55 | ); |
|
| 56 | ||
| 57 | return ConnectionBuilder::connectionFromArray($commentViewModelList); |
|
| 58 | } |
|
| 59 | ||
| 60 | public function countEdges(Connection $connection): int |
|
| 61 | { |
|
| 62 | return count($connection->edges); |
|
| 63 | } |
|
| 64 | } |
|
| 65 | ||
| @@ 28-64 (lines=37) @@ | ||
| 25 | use function array_map; |
|
| 26 | use function count; |
|
| 27 | ||
| 28 | final class PostTagsResolver |
|
| 29 | { |
|
| 30 | /** |
|
| 31 | * @var TagRepositoryInterface |
|
| 32 | */ |
|
| 33 | private $tagRepository; |
|
| 34 | ||
| 35 | public function __construct( |
|
| 36 | TagRepositoryInterface $tagRepository |
|
| 37 | ) { |
|
| 38 | $this->tagRepository = $tagRepository; |
|
| 39 | } |
|
| 40 | ||
| 41 | public function getPostTagsConnection(PostId $postId): Connection |
|
| 42 | { |
|
| 43 | try { |
|
| 44 | /** @var Collection $postTagList */ |
|
| 45 | $postTagList = $this->tagRepository->findAllByPostId($postId); |
|
| 46 | } catch (EmptyQueryResultException $e) { |
|
| 47 | return ConnectionBuilder::connectionFromArray([]); |
|
| 48 | } |
|
| 49 | ||
| 50 | $tagViewModelList = array_map( |
|
| 51 | function (Tag $tag) { |
|
| 52 | return TagViewModel::constructFromEntity($tag); |
|
| 53 | }, |
|
| 54 | $postTagList->toArray() |
|
| 55 | ); |
|
| 56 | ||
| 57 | return ConnectionBuilder::connectionFromArray($tagViewModelList); |
|
| 58 | } |
|
| 59 | ||
| 60 | public function countEdges(Connection $connection): int |
|
| 61 | { |
|
| 62 | return count($connection->edges); |
|
| 63 | } |
|
| 64 | } |
|
| 65 | ||