ClassMapBuildCompilerPassTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 37.7 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 23
loc 61
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testProcessEmpty() 0 11 1
A testProcess() 0 14 1
A testSkipEmptyClass() 11 11 1
A testSkipAbstract() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Skrz\Bundle\AutowiringBundle\Tests\DependencyInjection\Compiler;
3
4
use PHPUnit\Framework\TestCase;
5
use Psr\Container\ContainerInterface as PsrContainerInterface;
6
use Skrz\Bundle\AutowiringBundle\DependencyInjection\ClassMultiMap;
7
use Skrz\Bundle\AutowiringBundle\DependencyInjection\Compiler\ClassMapBuildCompilerPass;
8
use Skrz\Bundle\AutowiringBundle\Tests\DependencyInjection\ClassMultipleMapSource\SomeClass;
9
use Skrz\Bundle\AutowiringBundle\Tests\DependencyInjection\ClassMultipleMapSource\SomeInterface;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
use Symfony\Component\DependencyInjection\ContainerInterface;
12
use Symfony\Component\DependencyInjection\Definition;
13
14
class ClassMapBuildCompilerPassTest extends TestCase
15
{
16
17
	const EMPTY_BUILDER_MAP = [
18
		PsrContainerInterface::class => ["service_container"],
19
		ContainerInterface::class => ["service_container"],
20
	];
21
22
	public function testProcessEmpty()
23
	{
24
		$containerBuilder = new ContainerBuilder();
25
		$map = new ClassMultiMap(new ContainerBuilder());
26
		$pass = new ClassMapBuildCompilerPass($map);
27
28
		$pass->process($containerBuilder);
29
		$container = $map->all();
30
31
		$this->assertSame(static::EMPTY_BUILDER_MAP, $container);
32
	}
33
34
	public function testProcess()
35
	{
36
		$containerBuilder = new ContainerBuilder();
37
		$map = new ClassMultiMap(new ContainerBuilder());
38
		$pass = new ClassMapBuildCompilerPass($map);
39
40
		$containerBuilder
41
			->setDefinition("someService", new Definition(SomeClass::class));
42
		$pass->process($containerBuilder);
43
		$this->assertSame(array_merge(static::EMPTY_BUILDER_MAP, [
44
			SomeInterface::class => ["someService"],
45
			SomeClass::class => ["someService"]
46
		]), $map->all());
47
	}
48
49 View Code Duplication
	public function testSkipEmptyClass()
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...
50
	{
51
		$containerBuilder = new ContainerBuilder();
52
		$map = new ClassMultiMap(new ContainerBuilder());
53
		$pass = new ClassMapBuildCompilerPass($map);
54
55
		$containerBuilder
56
			->setDefinition("someService", new Definition());
57
		$pass->process($containerBuilder);
58
		$this->assertSame(static::EMPTY_BUILDER_MAP, $map->all());
59
	}
60
61 View Code Duplication
	public function testSkipAbstract()
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...
62
	{
63
		$containerBuilder = new ContainerBuilder();
64
		$map = new ClassMultiMap(new ContainerBuilder());
65
		$pass = new ClassMapBuildCompilerPass($map);
66
67
		$containerBuilder
68
			->setDefinition("someService", new Definition(SomeClass::class))
69
			->setAbstract(true);
70
		$pass->process($containerBuilder);
71
		$this->assertSame(static::EMPTY_BUILDER_MAP, $map->all());
72
	}
73
74
}
75