ClassMultiMapTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 29.31 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 17
loc 58
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetSingleForSimpleClass() 10 10 1
A testGetSingleForSimpleForInterface() 7 7 1
A testGetSingleForNonAddedClass() 0 7 1
A testGetSingleForClassAddedTwice() 0 10 1
A testGetMultiForNonAddedClass() 0 6 1
A testGetMultiForClassAddedTwice() 0 8 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;
3
4
use PHPUnit\Framework\TestCase;
5
use Skrz\Bundle\AutowiringBundle\DependencyInjection\ClassMultiMap;
6
use Skrz\Bundle\AutowiringBundle\Exception\MultipleValuesException;
7
use Skrz\Bundle\AutowiringBundle\Exception\NoValueException;
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
12
class ClassMultiMapTest extends TestCase
13
{
14
15 View Code Duplication
	public function testGetSingleForSimpleClass()
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...
16
	{
17
		$map = new ClassMultiMap(new ContainerBuilder());
18
19
		$map->put(SomeClass::class, "someValue");
20
		$this->assertSame(
21
			"someValue",
22
			$map->getSingle(SomeClass::class)
23
		);
24
	}
25
26 View Code Duplication
	public function testGetSingleForSimpleForInterface()
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...
27
	{
28
		$map = new ClassMultiMap(new ContainerBuilder());
29
30
		$map->put(SomeClass::class, "someValue");
31
		$this->assertSame("someValue", $map->getSingle(SomeInterface::class));
32
	}
33
34
	public function testGetSingleForNonAddedClass()
35
	{
36
		$this->expectException(NoValueException::class);
37
38
		$map = new ClassMultiMap(new ContainerBuilder());
39
		$map->getSingle(SomeClass::class);
40
	}
41
42
	public function testGetSingleForClassAddedTwice()
43
	{
44
		$this->expectException(MultipleValuesException::class);
45
46
		$map = new ClassMultiMap(new ContainerBuilder());
47
48
		$map->put(SomeClass::class, "someValue");
49
		$map->put(SomeClass::class, "someOtherValue");
50
		$map->getSingle(SomeClass::class);
51
	}
52
53
	public function testGetMultiForNonAddedClass()
54
	{
55
		$map = new ClassMultiMap(new ContainerBuilder());
56
57
		$this->assertSame([], $map->getMulti(SomeClass::class));
58
	}
59
60
	public function testGetMultiForClassAddedTwice()
61
	{
62
		$map = new ClassMultiMap(new ContainerBuilder());
63
64
		$map->put(SomeClass::class, "someValue");
65
		$map->put(SomeClass::class, "someOtherValue");
66
		$this->assertSame(["someValue", "someOtherValue"], $map->getMulti(SomeClass::class));
67
	}
68
69
}
70