Completed
Push — master ( c495da...16538c )
by Tomáš
14:54 queued 04:46
created

UserBundleExtension::getEntityMappings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SixtyEightPublishers\User\DI;
6
7
use ArrayObject;
8
use Nette\Schema\Expect;
9
use Nette\Schema\Schema;
10
use Nette\DI\CompilerExtension;
11
use Nette\PhpGenerator\ClassType;
12
use SixtyEightPublishers\User\Common\DI\CommonExtension;
13
use SixtyEightPublishers\User\Authentication\DI\AuthenticationExtension;
14
use SixtyEightPublishers\User\Common\Exception\StopPropagationException;
15
use SixtyEightPublishers\User\ForgotPassword\DI\ForgotPasswordExtension;
16
use SixtyEightPublishers\DoctrineBridge\DI\DatabaseTypeProviderInterface;
17
use SixtyEightPublishers\DoctrineBridge\DI\TargetEntityProviderInterface;
18
use SixtyEightPublishers\DoctrineBridge\DI\EntityMappingProviderInterface;
19
use SixtyEightPublishers\TranslationBridge\DI\TranslationProviderInterface;
20
use SixtyEightPublishers\User\DoctrineIdentity\DI\DoctrineIdentityExtension;
21
22
final class UserBundleExtension extends CompilerExtension implements DatabaseTypeProviderInterface, EntityMappingProviderInterface, TargetEntityProviderInterface, TranslationProviderInterface
23
{
24
	/** @var \Nette\DI\CompilerExtension[] */
25
	private $extensions;
26
27
	public function __construct()
28
	{
29
		$this->extensions = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array('common' => new \S...henticationExtension()) of type array<string,object<Sixt...enticationExtension>"}> is incompatible with the declared type array<integer,object<Nette\DI\CompilerExtension>> of property $extensions.

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..

Loading history...
30
			'common' => new CommonExtension(),
31
			'doctrine_identity' => new DoctrineIdentityExtension(),
32
			'forgot_password' => new ForgotPasswordExtension(),
33
			'authentication' => new AuthenticationExtension(),
34
		];
35
	}
36
37
	/**
38
	 * {@inheritDoc}
39
	 */
40
	public function getConfigSchema(): Schema
41
	{
42
		return Expect::structure(array_map(static function (CompilerExtension $extension) {
43
			return $extension->getConfigSchema();
44
		}, $this->extensions));
45
	}
46
47
	/**
48
	 * {@inheritDoc}
49
	 */
50
	public function loadConfiguration(): void
51
	{
52
		$config = $this->config;
53
		$sharedData = new ArrayObject();
54
55
		foreach ($config as $extName => $extConfig) {
56
			$extension = $this->extensions[$extName];
57
			$extension->setCompiler($this->compiler, $this->prefix($extName));
58
			$extension->setConfig($extConfig);
59
60
			if ($extension instanceof CompilerExtensionPassInterface) {
61
				$extension->attach($this, $sharedData);
62
			}
63
		}
64
65
		foreach ($this->extensions as $name => $extension) {
66
			try {
67
				if ($extension instanceof CompilerExtensionPassInterface) {
68
					$extension->startup();
69
				}
70
			} catch (StopPropagationException $e) {
71
				unset($this->extensions[$name]);
72
73
				continue;
74
			}
75
76
			$extension->loadConfiguration();
77
		}
78
	}
79
80
	/**
81
	 * {@inheritDoc}
82
	 */
83
	public function beforeCompile(): void
84
	{
85
		foreach ($this->extensions as $extension) {
86
			$extension->beforeCompile();
87
		}
88
	}
89
90
	/**
91
	 * {@inheritDoc}
92
	 */
93
	public function afterCompile(ClassType $class): void
94
	{
95
		foreach ($this->extensions as $extension) {
96
			$extension->afterCompile($class);
97
		}
98
	}
99
100
	/**
101
	 * {@inheritDoc}
102
	 */
103 View Code Duplication
	public function getDatabaseTypes(): 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...
104
	{
105
		return array_merge([], ...array_map(static function (DatabaseTypeProviderInterface $provider) {
106
			return $provider->getDatabaseTypes();
107
		}, array_filter(array_values($this->extensions), static function ($extension) {
108
			return $extension instanceof DatabaseTypeProviderInterface;
109
		})));
110
	}
111
112
	/**
113
	 * {@inheritDoc}
114
	 */
115 View Code Duplication
	public function getEntityMappings(): 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...
116
	{
117
		return array_merge([], ...array_map(static function (EntityMappingProviderInterface $provider) {
118
			return $provider->getEntityMappings();
119
		}, array_filter(array_values($this->extensions), static function ($extension) {
120
			return $extension instanceof EntityMappingProviderInterface;
121
		})));
122
	}
123
124
	/**
125
	 * {@inheritDoc}
126
	 */
127 View Code Duplication
	public function getTargetEntities(): 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...
128
	{
129
		return array_merge([], ...array_map(static function (TargetEntityProviderInterface $provider) {
130
			return $provider->getTargetEntities();
131
		}, array_filter(array_values($this->extensions), static function ($extension) {
132
			return $extension instanceof TargetEntityProviderInterface;
133
		})));
134
	}
135
136
	/**
137
	 * {@inheritDoc}
138
	 */
139 View Code Duplication
	public function getTranslationResources(): 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...
140
	{
141
		return array_merge([], ...array_map(static function (TranslationProviderInterface $provider) {
142
			return $provider->getTranslationResources();
143
		}, array_filter(array_values($this->extensions), static function ($extension) {
144
			return $extension instanceof TranslationProviderInterface;
145
		})));
146
	}
147
}
148