AbstractBehaviorExtension   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 41
c 0
b 0
f 0
wmc 6
lcom 1
cbo 5
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildDefinitionFromCallable() 0 20 4
A getClassAnalyzer() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Zenify
7
 * Copyright (c) 2012 Tomas Votruba (http://tomasvotruba.cz)
8
 */
9
10
namespace Zenify\DoctrineBehaviors\DI;
11
12
use Knp\DoctrineBehaviors\Reflection\ClassAnalyzer;
13
use Nette\DI\Compiler;
14
use Nette\DI\CompilerExtension;
15
use Nette\DI\ServiceDefinition;
16
use Nette\DI\Statement;
17
18
19
abstract class AbstractBehaviorExtension extends CompilerExtension
20
{
21
22 2
	protected function getClassAnalyzer() : ServiceDefinition
23
	{
24 2
		$builder = $this->getContainerBuilder();
25
26 2
		if ($builder->hasDefinition('knp.classAnalyzer')) {
27 2
			return $builder->getDefinition('knp.classAnalyzer');
28
		}
29
30 2
		return $builder->addDefinition('knp.classAnalyzer')
31 2
			->setClass(ClassAnalyzer::class);
32
	}
33
34
35
	/**
36
	 * @return ServiceDefinition|NULL
37
	 */
38 3
	protected function buildDefinitionFromCallable(string $callable = NULL)
39
	{
40 3
		if ($callable === NULL) {
41 2
			return NULL;
42
		}
43
44 2
		$builder = $this->getContainerBuilder();
45 2
		$definition = $builder->addDefinition($this->prefix(md5($callable)));
46
47 2
		list($definition->factory) = Compiler::filterArguments([
0 ignored issues
show
Deprecated Code introduced by
The method Nette\DI\Compiler::filterArguments() has been deprecated.

This method has been deprecated.

Loading history...
48 2
			is_string($callable) ? new Statement($callable) : $callable
49
		]);
50
51 2
		list($resolverClass) = (array) $builder->normalizeEntity($definition->getFactory()->getEntity());
52 2
		if (class_exists($resolverClass)) {
53 2
			$definition->setClass($resolverClass);
54
		}
55
56 2
		return $definition;
57
	}
58
59
}
60