Completed
Push — master ( f571ad...af881e )
by Gorka
10s
created

TaskResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 3
dl 9
loc 9
rs 9.6666
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\TaskManager\Infrastructure\Ui\Http\GraphQl\Query\Project\Task;
16
17
use Kreta\SharedKernel\Application\QueryBus;
18
use Kreta\SharedKernel\Http\GraphQl\Resolver;
19
use Kreta\TaskManager\Application\Query\Project\Task\TaskOfIdQuery;
20
use Kreta\TaskManager\Infrastructure\Ui\Http\GraphQl\Query\Project\ProjectResolver;
21
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
22
23 View Code Duplication
class TaskResolver implements Resolver
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
{
25
    private $queryBus;
26
    private $currentUser;
27
    private $projectResolver;
28
29
    public function __construct(
30
        TokenStorageInterface $tokenStorage,
31
        QueryBus $queryBus,
32
        ProjectResolver $projectResolver
33
    ) {
34
        $this->queryBus = $queryBus;
35
        $this->currentUser = $tokenStorage->getToken()->getUser()->getUsername();
36
        $this->projectResolver = $projectResolver;
37
    }
38
39
    public function resolve($args)
40
    {
41
        $this->queryBus->handle(
42
            new TaskOfIdQuery(
43
                $args['id'],
44
                $this->currentUser
45
            ),
46
            $result
47
        );
48
49
        $result['project'] = $this->projectResolver->resolve([
50
            'id' => $result['project_id'],
51
        ]);
52
        unset($result['project_id']);
53
54
        return $result;
55
    }
56
}
57