1 | <?php |
||
2 | |||
3 | |||
4 | namespace TheCodingMachine\GraphQL\Controllers; |
||
5 | |||
6 | use Psr\Container\ContainerInterface; |
||
7 | use TheCodingMachine\GraphQL\Controllers\Mappers\RecursiveTypeMapperInterface; |
||
8 | |||
9 | /** |
||
10 | * A query provider that looks into all controllers of your application to fetch queries. |
||
11 | */ |
||
12 | class AggregateControllerQueryProvider implements QueryProviderInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var array|string[] |
||
16 | */ |
||
17 | private $controllers; |
||
18 | /** |
||
19 | * @var ContainerInterface |
||
20 | */ |
||
21 | private $controllersContainer; |
||
22 | /** |
||
23 | * @var FieldsBuilderFactory |
||
24 | */ |
||
25 | private $queryProviderFactory; |
||
26 | /** |
||
27 | * @var RecursiveTypeMapperInterface |
||
28 | */ |
||
29 | private $recursiveTypeMapper; |
||
30 | |||
31 | /** |
||
32 | * @param string[] $controllers A list of controllers name in the container. |
||
33 | * @param FieldsBuilderFactory $queryProviderFactory |
||
34 | * @param ContainerInterface $controllersContainer The container we will fetch controllers from. |
||
35 | */ |
||
36 | public function __construct(iterable $controllers, FieldsBuilderFactory $queryProviderFactory, RecursiveTypeMapperInterface $recursiveTypeMapper, ContainerInterface $controllersContainer) |
||
37 | { |
||
38 | $this->controllers = $controllers; |
||
0 ignored issues
–
show
|
|||
39 | $this->queryProviderFactory = $queryProviderFactory; |
||
40 | $this->controllersContainer = $controllersContainer; |
||
41 | $this->recursiveTypeMapper = $recursiveTypeMapper; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @return QueryField[] |
||
46 | */ |
||
47 | public function getQueries(): array |
||
48 | { |
||
49 | $queryList = []; |
||
50 | |||
51 | foreach ($this->controllers as $controllerName) { |
||
52 | $controller = $this->controllersContainer->get($controllerName); |
||
53 | $queryProvider = $this->queryProviderFactory->buildFieldsBuilder($this->recursiveTypeMapper); |
||
54 | $queryList = array_merge($queryList, $queryProvider->getQueries($controller)); |
||
55 | } |
||
56 | |||
57 | return $queryList; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @return QueryField[] |
||
62 | */ |
||
63 | public function getMutations(): array |
||
64 | { |
||
65 | $mutationList = []; |
||
66 | |||
67 | foreach ($this->controllers as $controllerName) { |
||
68 | $controller = $this->controllersContainer->get($controllerName); |
||
69 | $queryProvider = $this->queryProviderFactory->buildFieldsBuilder($this->recursiveTypeMapper); |
||
70 | $mutationList = array_merge($mutationList, $queryProvider->getMutations($controller)); |
||
71 | } |
||
72 | |||
73 | return $mutationList; |
||
74 | } |
||
75 | } |
||
76 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..