Completed
Push — master ( 674d5a...194be7 )
by Gorka
04:12
created

OrganizationResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 1 Features 1
Metric Value
dl 0
loc 36
rs 10
c 2
b 1
f 1
wmc 3
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B resolve() 0 24 2
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\Query\Organization;
16
17
use Kreta\SharedKernel\Application\QueryBus;
18
use Kreta\SharedKernel\Http\GraphQl\Resolver;
19
use Kreta\TaskManager\Application\Query\Organization\OrganizationOfIdQuery;
20
use Kreta\TaskManager\Application\Query\Organization\OrganizationOfSlugQuery;
21
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
22
23
class OrganizationResolver implements Resolver
24
{
25
    private $queryBus;
26
    private $currentUser;
27
28
    public function __construct(TokenStorageInterface $tokenStorage, QueryBus $queryBus)
29
    {
30
        $this->queryBus = $queryBus;
31
        $this->currentUser = $tokenStorage->getToken()->getUser()->getUsername();
32
    }
33
34
    public function resolve($args)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
35
    {
36
        if (isset($args['id'])) {
37
            $this->queryBus->handle(
38
                new OrganizationOfIdQuery(
39
                    $args['id'],
40
                    $this->currentUser
41
                ),
42
                $result
43
            );
44
45
            return $result;
46
        }
47
48
        $this->queryBus->handle(
49
            new OrganizationOfSlugQuery(
50
                $args['slug'],
51
                $this->currentUser
52
            ),
53
            $result
54
        );
55
56
        return $result;
57
    }
58
}
59