Completed
Push — master ( b19cf5...8a98cd )
by Tomáš
03:10
created

GraphQLExtension::setupRequestProcessor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Portiny\GraphQL\Adapter\Nette\DI;
6
7
use Nette\DI\Compiler;
8
use Nette\DI\CompilerExtension;
9
use Portiny\GraphQL\Contract\Field\QueryFieldInterface;
10
use Portiny\GraphQL\Contract\Mutation\MutationFieldInterface;
11
use Portiny\GraphQL\Contract\Provider\MutationFieldsProviderInterface;
12
use Portiny\GraphQL\Contract\Provider\QueryFieldsProviderInterface;
13
use Portiny\GraphQL\GraphQL\RequestProcessor;
14
use Portiny\GraphQL\Provider\MutationFieldsProvider;
15
use Portiny\GraphQL\Provider\QueryFieldsProvider;
16
17
final class GraphQLExtension extends CompilerExtension
18
{
19
	/**
20
	 * {@inheritdoc}
21
	 */
22
	public function loadConfiguration(): void
23
	{
24 1
		$builder = $this->getContainerBuilder();
25
		$config = $this->loadFromFile(__DIR__ . '/../config/config.neon');
26 1
		Compiler::loadDefinitions($builder, $config['services'] ?: []);
27 1
	}
28 1
29 1
	/**
30
	 * {@inheritdoc}
31
	 */
32
	public function beforeCompile(): void
33
	{
34
		$this->setupMutationFieldProvider();
35 1
		$this->setupQueryFieldProvider();
36
		$this->setupRequestProcessor();
37 1
	}
38 1
39 1 View Code Duplication
	private function setupMutationFieldProvider(): void
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...
40 1
	{
41
		$containerBuilder = $this->getContainerBuilder();
42
43 1
		$mutationFieldProvider = $containerBuilder->addDefinition($this->prefix('mutationFieldsProvider'))
44
			->setFactory(MutationFieldsProvider::class)
45 1
			->setType(MutationFieldsProviderInterface::class)
46
			->setInject(FALSE);
47 1
48 1
		$mutationFieldDefinitions = $containerBuilder->findByType(MutationFieldInterface::class);
49 1
		foreach ($mutationFieldDefinitions as $mutationFieldDefinition) {
50 1
			$mutationFieldProvider->addSetup('addField', ['@' . $mutationFieldDefinition->getType()]);
51
		}
52 1
	}
53 1
54 1 View Code Duplication
	private function setupQueryFieldProvider(): void
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...
55
	{
56 1
		$containerBuilder = $this->getContainerBuilder();
57
58
		$queryFieldProvider = $containerBuilder->addDefinition($this->prefix('queryFieldsProvider'))
59 1
			->setFactory(QueryFieldsProvider::class)
60
			->setType(QueryFieldsProviderInterface::class)
61 1
			->setInject(FALSE);
62
63 1
		$queryFieldDefinitions = $containerBuilder->findByType(QueryFieldInterface::class);
64 1
		foreach ($queryFieldDefinitions as $queryFieldDefinition) {
65 1
			$queryFieldProvider->addSetup('addField', ['@' . $queryFieldDefinition->getType()]);
66 1
		}
67
	}
68 1
69 1
	private function setupRequestProcessor(): void
70 1
	{
71
		$containerBuilder = $this->getContainerBuilder();
72 1
73
		$containerBuilder->addDefinition($this->prefix('requestProcessor'))
74
			->setFactory(RequestProcessor::class)
75 1
			->addSetup('setMutationFieldsProvider', ['@' . MutationFieldsProviderInterface::class])
76
			->addSetup('setQueryFieldsProvider', ['@' . QueryFieldsProviderInterface::class]);
77 1
	}
78
}
79