Completed
Push — master ( acb1bd...aa3a2b )
by Rafael
02:57
created

ArrayDebuggerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 116
Duplicated Lines 88.79 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 1
dl 103
loc 116
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B testGetter() 25 25 1
B testSetter() 25 25 1
B testIsset() 27 27 1
B testUnset() 26 26 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 PHP;
4
5
class ArrayDebuggerTest extends \PHPUnit_Framework_TestCase 
6
{
7
8
  public $base = array(
9
    'hum'  => 1, 
10
    'dois' => 2, 
11
    'tres' => 3
12
  );
13
14 View Code Duplication
  public function testGetter() {
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
16
    $array = new ArrayDebugger($this->base);
17
18
    $array->setLogger(function($retorno)  {
19
      $this->assertEquals($retorno['type'], ArrayDebugger::TYPE_GET);
20
    });
21
22
    $teste = $array['hum'];
0 ignored issues
show
Unused Code introduced by
$teste is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
23
24
    $array->setLogger(function($retorno) {
25
      $this->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_GET);
26
    });
27
28
    $array['quatro'] = 4;
29
30
    /**
31
     * offsetExists
32
     */
33
    isset($array['hum']);
34
    /**
35
     * offsetUnset
36
     */
37
    unset($array['quatro']);
38
  }
39
40 View Code Duplication
  public function testSetter() {
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...
41
42
    $array = new ArrayDebugger($this->base);
43
44
    $array->setLogger(function($retorno)  {
45
      $this->assertEquals($retorno['type'], ArrayDebugger::TYPE_SET);
46
    });
47
48
    $array['quatro'] = 4;
49
50
    $array->setLogger(function($retorno) {
51
      $this->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_SET);
52
    });
53
54
    $teste = $array['hum'];
0 ignored issues
show
Unused Code introduced by
$teste is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
55
56
    /**
57
     * offsetExists
58
     */
59
    isset($array['hum']);
60
    /**
61
     * offsetUnset
62
     */
63
    unset($array['quatro']);
64
  }
65
66 View Code Duplication
  public function testIsset() {
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...
67
68
    $array = new ArrayDebugger($this->base);
69
70
    $array->setLogger(function($retorno)  {
71
      $this->assertEquals($retorno['type'], ArrayDebugger::TYPE_EXISTS);
72
    });
73
74
75
    /**
76
     * offsetExists
77
     */
78
    isset($array['hum']);
79
80
    $array->setLogger(function($retorno) {
81
      $this->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_EXISTS);
82
    });
83
84
    $array['quatro'] = 4;
85
86
    $teste = $array['hum'];
0 ignored issues
show
Unused Code introduced by
$teste is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
87
88
    /**
89
     * offsetUnset
90
     */
91
    unset($array['quatro']);
92
  }
93
94 View Code Duplication
  public function testUnset() {
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...
95
96
    $array = new ArrayDebugger($this->base);
97
98
    $array->setLogger(function($retorno)  {
99
      $this->assertEquals($retorno['type'], ArrayDebugger::TYPE_UNSET);
100
    });
101
102
    /**
103
     * offsetUnset
104
     */
105
    unset($array['dois']);
106
107
    $array->setLogger(function($retorno) {
108
      $this->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_UNSET);
109
    });
110
    /**
111
     * offsetExists
112
     */
113
    isset($array['hum']);
114
115
    $array['quatro'] = 4;
116
117
    $teste = $array['hum'];
0 ignored issues
show
Unused Code introduced by
$teste is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
118
119
  }
120
}
121