Code Duplication    Length = 35-36 lines in 2 locations

TaskManager/src/Kreta/TaskManager/Infrastructure/Ui/Http/GraphQl/Mutation/Organization/CreateOrganizationMutation.php 1 location

@@ 24-58 (lines=35) @@
21
use Kreta\TaskManager\Application\Query\Organization\OrganizationOfIdQuery;
22
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
23
24
class CreateOrganizationMutation implements Mutation
25
{
26
    private $commandBus;
27
    private $queryBus;
28
    private $currentUser;
29
30
    public function __construct(TokenStorageInterface $tokenStorage, CommandBus $commandBus, QueryBus $queryBus)
31
    {
32
        $this->queryBus = $queryBus;
33
        $this->commandBus = $commandBus;
34
        $this->currentUser = $tokenStorage->getToken()->getUser()->getUsername();
35
    }
36
37
    public function execute(array $values) : array
38
    {
39
        $command = new CreateOrganizationCommand(
40
            $this->currentUser,
41
            $values['name']
42
        );
43
44
        $this->commandBus->handle($command);
45
46
        $this->queryBus->handle(
47
            new OrganizationOfIdQuery(
48
                $command->id(),
49
                $this->currentUser
50
            ),
51
            $organization
52
        );
53
54
        return [
55
            'organization' => $organization,
56
        ];
57
    }
58
}
59

TaskManager/src/Kreta/TaskManager/Infrastructure/Ui/Http/GraphQl/Query/Project/Task/TaskResolver.php 1 location

@@ 22-57 (lines=36) @@
19
use Kreta\TaskManager\Application\Query\Project\Task\TaskOfIdQuery;
20
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
21
22
class TaskResolver implements Resolver
23
{
24
    private $queryBus;
25
    private $currentUser;
26
    private $taskBuilderResolver;
27
28
    public function __construct(
29
        TokenStorageInterface $tokenStorage,
30
        QueryBus $queryBus,
31
        TaskBuilderResolver $taskBuilderResolver
32
    ) {
33
        $this->queryBus = $queryBus;
34
        $this->currentUser = $tokenStorage->getToken()->getUser()->getUsername();
35
        $this->taskBuilderResolver = $taskBuilderResolver;
36
    }
37
38
    public function resolve($args)
39
    {
40
        $this->queryBus->handle(
41
            new TaskOfIdQuery(
42
                $args['id'],
43
                $this->currentUser
44
            ),
45
            $result
46
        );
47
48
        $result = $this->taskBuilderResolver->resolve($result);
49
50
        return $result;
51
    }
52
53
    public function resolveByParent($parentId)
54
    {
55
        return $this->resolve(['id' => $parentId]);
56
    }
57
}
58