Completed
Push — master ( 7eaefb...72c28c )
by
unknown
03:02
created

src/DI/TimestampableExtension.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * This file is part of Zenify
5
 * Copyright (c) 2012 Tomas Votruba (http://tomasvotruba.cz)
6
 */
7
8
namespace Zenify\DoctrineBehaviors\DI;
9
10
use Kdyby\Events\DI\EventsExtension;
11
use Knp\DoctrineBehaviors\Model\Timestampable\Timestampable;
12
use Knp\DoctrineBehaviors\ORM\Timestampable\TimestampableSubscriber;
13
use Nette\Utils\AssertionException;
14
use Nette\Utils\Validators;
15
16
17 View Code Duplication
final class TimestampableExtension extends AbstractBehaviorExtension
0 ignored issues
show
This class 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...
18
{
19
20
	/**
21
	 * @var array
22
	 */
23
	private $default = [
24
		'isRecursive' => TRUE,
25
		'trait' => Timestampable::class
26
	];
27
28
29
	public function loadConfiguration()
30
	{
31
		$config = $this->getConfig($this->default);
32
		$this->validateConfigTypes($config);
33
		$builder = $this->getContainerBuilder();
34
35
		$builder->addDefinition($this->prefix('listener'))
36
			->setClass(TimestampableSubscriber::class, [
37
				'@' . $this->getClassAnalyzer()->getClass(),
38
				$config['isRecursive'],
39
				$config['trait']
40
			])
41
			->setAutowired(FALSE)
42
			->addTag(EventsExtension::TAG_SUBSCRIBER);
43
	}
44
45
46
	/**
47
	 * @throws AssertionException
48
	 */
49
	private function validateConfigTypes(array $config)
50
	{
51
		Validators::assertField($config, 'isRecursive', 'bool');
52
		Validators::assertField($config, 'trait', 'type');
53
	}
54
55
}
56