Completed
Push — master ( 5aeb74...106e30 )
by David
01:50
created

AggregateControllerQueryProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 44.16 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 34
loc 77
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 10 10 1
A getQueries() 12 12 2
A getMutations() 12 12 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
4
namespace TheCodingMachine\GraphQL\Controllers;
5
6
use phpDocumentor\Reflection\Type;
7
use phpDocumentor\Reflection\Types\Array_;
8
use phpDocumentor\Reflection\Types\Mixed;
9
use phpDocumentor\Reflection\Types\Object_;
10
use phpDocumentor\Reflection\Types\String_;
11
use Psr\Container\ContainerInterface;
12
use Roave\BetterReflection\Reflection\ReflectionClass;
13
use Roave\BetterReflection\Reflection\ReflectionMethod;
14
use Doctrine\Common\Annotations\Reader;
15
use phpDocumentor\Reflection\Types\Integer;
16
use TheCodingMachine\GraphQL\Controllers\Annotations\Query;
17
use TheCodingMachine\GraphQL\Controllers\Security\AuthenticationServiceInterface;
18
use TheCodingMachine\GraphQL\Controllers\Security\AuthorizationServiceInterface;
19
use Youshido\GraphQL\Field\Field;
20
use Youshido\GraphQL\Type\ListType\ListType;
21
use Youshido\GraphQL\Type\NonNullType;
22
use Youshido\GraphQL\Type\Scalar\IntType;
23
use Youshido\GraphQL\Type\Scalar\StringType;
24
use Youshido\GraphQL\Type\TypeInterface;
25
use Youshido\GraphQL\Type\Union\UnionType;
26
27
/**
28
 * A query provider that looks into all controllers of your application to fetch queries.
29
 */
30
class AggregateControllerQueryProvider implements QueryProviderInterface
31
{
32
    /**
33
     * @var Reader
34
     */
35
    private $annotationReader;
36
    /**
37
     * @var TypeMapperInterface
38
     */
39
    private $typeMapper;
40
    /**
41
     * @var HydratorInterface
42
     */
43
    private $hydrator;
44
    /**
45
     * @var array|\string[]
46
     */
47
    private $controllers;
48
    /**
49
     * @var ContainerInterface
50
     */
51
    private $container;
52
    /**
53
     * @var AuthenticationServiceInterface
54
     */
55
    private $authenticationService;
56
    /**
57
     * @var AuthorizationServiceInterface
58
     */
59
    private $authorizationService;
60
61
    /**
62
     * @param string[] $controllers A list of controllers name in the container.
63
     */
64 View Code Duplication
    public function __construct(array $controllers, ContainerInterface $container, Reader $annotationReader, TypeMapperInterface $typeMapper, HydratorInterface $hydrator, AuthenticationServiceInterface $authenticationService, AuthorizationServiceInterface $authorizationService)
0 ignored issues
show
Duplication introduced by
This method 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...
65
    {
66
        $this->controllers = $controllers;
67
        $this->container = $container;
68
        $this->annotationReader = $annotationReader;
69
        $this->typeMapper = $typeMapper;
70
        $this->hydrator = $hydrator;
71
        $this->authenticationService = $authenticationService;
72
        $this->authorizationService = $authorizationService;
73
    }
74
75
    /**
76
     * @return Field[]
77
     */
78 View Code Duplication
    public function getQueries(): array
0 ignored issues
show
Duplication introduced by
This method 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...
79
    {
80
        $queryList = [];
81
82
        foreach ($this->controllers as $controllerName) {
83
            $controller = $this->container->get($controllerName);
84
            $queryProvider = new ControllerQueryProvider($controller, $this->annotationReader, $this->typeMapper, $this->hydrator, $this->authenticationService, $this->authorizationService);
85
            $queryList = array_merge($queryList, $queryProvider->getQueries());
86
        }
87
88
        return $queryList;
89
    }
90
91
    /**
92
     * @return Field[]
93
     */
94 View Code Duplication
    public function getMutations(): array
0 ignored issues
show
Duplication introduced by
This method 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...
95
    {
96
        $mutationList = [];
97
98
        foreach ($this->controllers as $controllerName) {
99
            $controller = $this->container->get($controllerName);
100
            $queryProvider = new ControllerQueryProvider($controller, $this->annotationReader, $this->typeMapper, $this->hydrator);
0 ignored issues
show
Bug introduced by
The call to ControllerQueryProvider::__construct() misses some required arguments starting with $authenticationService.
Loading history...
101
            $mutationList = array_merge($mutationList, $queryProvider->getMutations());
102
        }
103
104
        return $mutationList;
105
    }
106
}
107