buildDefinitionFromCallable()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 20
ccs 11
cts 11
cp 1
rs 9.2
cc 4
eloc 11
nc 3
nop 1
crap 4
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