ExactValueTokenTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 18.67 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 14
loc 75
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A does_not_trigger_nesting_error() 7 7 1
A scores_10_for_objects_with_same_fields() 7 7 1
A scores_10_for_matching_callables() 0 6 1
A scores_false_for_object_and_string() 0 6 1
A scores_false_for_object_and_int() 0 6 1
A scores_false_for_object_and_stdclass() 0 6 1
A scores_false_for_object_and_null() 0 6 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
3
namespace Tests\Prophecy\Argument\Token;
4
5
use PHPUnit\Framework\TestCase;
6
use Prophecy\Argument\Token\ExactValueToken;
7
8
class ExactValueTokenTest extends TestCase {
9
	/**
10
	 * @test
11
	 * @see https://github.com/phpspec/prophecy/issues/268
12
	 * @see https://stackoverflow.com/a/19097159/2424814
13
	 */
14 View Code Duplication
	public function does_not_trigger_nesting_error() {
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...
15
		$child1 = new ChildClass('A', new ParentClass());
16
		$child2 = new ChildClass('B', new ParentClass());
17
18
		$exactValueToken = new ExactValueToken($child1);
19
		self::assertEquals(false, $exactValueToken->scoreArgument($child2));
20
	}
21
22
	/**
23
	 * @test
24
	 */
25 View Code Duplication
	public function scores_10_for_objects_with_same_fields() {
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...
26
		$child1 = new ChildClass('A', new ParentClass());
27
		$child2 = new ChildClass('A', new ParentClass());
28
29
		$exactValueToken = new ExactValueToken($child1);
30
		self::assertEquals(10, $exactValueToken->scoreArgument($child2));
31
	}
32
33
    /**
34
     * @test
35
     */
36
    public function scores_10_for_matching_callables() {
37
        $callable = function() {};
38
39
        $exactValueToken = new ExactValueToken($callable);
40
        self::assertEquals(10, $exactValueToken->scoreArgument($callable));
41
    }
42
43
	/**
44
	 * @test
45
	 */
46
	public function scores_false_for_object_and_string() {
47
		$child1 = new ChildClass('A', new ParentClass());
48
49
		$exactValueToken = new ExactValueToken($child1);
50
		self::assertEquals(false, $exactValueToken->scoreArgument("A"));
51
	}
52
53
	/**
54
	 * @test
55
	 */
56
	public function scores_false_for_object_and_int() {
57
		$child1 = new ChildClass('A', new ParentClass());
58
59
		$exactValueToken = new ExactValueToken($child1);
60
		self::assertEquals(false, $exactValueToken->scoreArgument(100));
61
	}
62
63
	/**
64
	 * @test
65
	 */
66
	public function scores_false_for_object_and_stdclass() {
67
		$child1 = new ChildClass('A', new ParentClass());
68
69
		$exactValueToken = new ExactValueToken($child1);
70
		self::assertEquals(false, $exactValueToken->scoreArgument(new \stdClass()));
71
	}
72
73
	/**
74
	 * @test
75
	 */
76
	public function scores_false_for_object_and_null() {
77
		$child1 = new ChildClass('A', new ParentClass());
78
79
		$exactValueToken = new ExactValueToken($child1);
80
		self::assertEquals(false, $exactValueToken->scoreArgument(null));
81
	}
82
}
83
84
85
class ParentClass {
86
87
	public $children = array();
88
89
	public function addChild($child) {
90
		$this->children[] = $child;
91
	}
92
}
93
94
class ChildClass {
95
96
	public $parent = null;
97
	public $name = null;
98
99
	public function __construct($name, $parent) {
100
		$this->name = $name;
101
		$this->parent = $parent;
102
		$this->parent->addChild($this);
103
	}
104
105
}
106