Test Setup Failed
Push — graphql_api ( 4ff753 )
by Herberto
07:48 queued 01:35
created

CreatedPostsResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getCreatedPostsConnection() 0 11 1
A countEdges() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Explicit Architecture POC,
7
 * which is created on top of the Symfony Demo application.
8
 *
9
 * (c) Herberto Graça <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Acme\App\Presentation\Api\GraphQl\Node\User\Connection\CreatedPosts;
16
17
use Acme\App\Core\Component\Blog\Application\Repository\PostRepositoryInterface;
18
use Acme\App\Core\Component\Blog\Domain\Post\Post;
19
use Acme\App\Core\SharedKernel\Component\User\Domain\User\UserId;
20
use Acme\App\Presentation\Api\GraphQl\Node\Post\PostViewModel;
21
use Overblog\GraphQLBundle\Relay\Connection\Output\Connection;
22
use Overblog\GraphQLBundle\Relay\Connection\Output\ConnectionBuilder;
23
use function array_map;
24
25
final class CreatedPostsResolver
26
{
27
    /**
28
     * @var PostRepositoryInterface
29
     */
30
    private $postRepository;
31
32
    public function __construct(
33
        PostRepositoryInterface $postRepository
34
    ) {
35
        $this->postRepository = $postRepository;
36
    }
37
38
    public function getCreatedPostsConnection(UserId $userId): Connection
39
    {
40
        $postViewModelList = array_map(
41
            function (Post $post) {
42
                return PostViewModel::constructFromEntity($post);
43
            },
44
            $this->postRepository->findAllByUserId($userId)->toArray()
45
        );
46
47
        return ConnectionBuilder::connectionFromArray($postViewModelList);
48
    }
49
50
    public function countEdges(Connection $connection): int
51
    {
52
        return count($connection->edges);
53
    }
54
}
55