DefinitionFinder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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\DoctrineFilters\DI;
11
12
use Nette\DI\ContainerBuilder;
13
use Nette\DI\ServiceDefinition;
14
use Zenify\DoctrineFilters\Exception\DefinitionForTypeNotFoundException;
15
16
17
final class DefinitionFinder
18
{
19
20
	/**
21
	 * @var ContainerBuilder
22
	 */
23
	private $containerBuilder;
24
25
26 6
	public function __construct(ContainerBuilder $containerBuilder)
27
	{
28 6
		$this->containerBuilder = $containerBuilder;
29 6
	}
30
31
32 5 View Code Duplication
	public function getDefinitionByType(string $type) : ServiceDefinition
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...
33
	{
34 5
		$this->containerBuilder->prepareClassList();
35
36 5
		if ($name = $this->containerBuilder->getByType($type)) {
37 3
			return $this->containerBuilder->getDefinition($name);
38
		}
39
40 4
		foreach ($this->containerBuilder->findByType($type) as $definition) {
41 3
			return $definition;
42
		}
43
44 1
		throw new DefinitionForTypeNotFoundException(
45 1
			sprintf('Definition for type "%s" was not found.', $type)
46
		);
47
	}
48
49
50 2 View Code Duplication
	public function getServiceNameByType(string $type) : string
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...
51
	{
52 2
		$this->containerBuilder->prepareClassList();
53
54 2
		if ($name = $this->containerBuilder->getByType($type)) {
55 2
			return $name;
56
		}
57
58
		foreach ($this->containerBuilder->findByType($type) as $name => $definition) {
59
			return $name;
60
		}
61
62
		throw new DefinitionForTypeNotFoundException(
63
			sprintf('Definition for type "%s" was not found.', $type)
64
		);
65
	}
66
67
}
68