Completed
Push — master ( 4030e5...50c1b3 )
by Gorka
11s
created

CreateTaskMutation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
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\Symfony\GraphQl\Mutation\Project\Task;
16
17
use Kreta\SharedKernel\Application\CommandBus;
18
use Kreta\SharedKernel\Http\GraphQl\Relay\Mutation;
19
use Kreta\TaskManager\Application\Command\Project\Task\CreateTaskCommand;
20
use Kreta\TaskManager\Infrastructure\Symfony\GraphQl\Query\Project\Task\TaskResolver;
21
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
22
23
class CreateTaskMutation implements Mutation
24
{
25
    private $commandBus;
26
    private $currentUser;
27
    private $taskResolver;
28
29
    public function __construct(TokenStorageInterface $tokenStorage, CommandBus $commandBus, TaskResolver $taskResolver)
30
    {
31
        $this->commandBus = $commandBus;
32
        $this->currentUser = $tokenStorage->getToken()->getUser()->getUsername();
33
        $this->taskResolver = $taskResolver;
34
    }
35
36
    public function execute(array $values) : array
37
    {
38
        $command = new CreateTaskCommand(
39
            $values['title'],
40
            $values['description'],
41
            $this->currentUser,
42
            $values['assigneeId'],
43
            $values['priority'],
44
            $values['projectId'],
45
            $values['parentId'] ?? null
46
        );
47
48
        $this->commandBus->handle($command);
49
50
        return [
51
            'task' => $this->taskResolver->resolve([
52
                'id' => $command->taskId(),
53
            ]),
54
        ];
55
    }
56
}
57