Completed
Push — BBD-667 ( b7f8e3 )
by Ben
05:37
created

ArrayUtilsTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 50 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 20
loc 40
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testRemoveFromArrayByIndex() 10 10 1
A testGetElementOnRemoveByIndex() 0 6 1
A testRemoveFromArray() 10 10 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
use GroupByInc\API\Util\ArrayUtils;
4
5
class ArrayUtilsTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7
    /** @var string[] */
8
    private $array;
9
10
    public function setUp()
11
    {
12
        $this->array = array("a", "bunch", "of", "words", "in", "an", "array");;
13
    }
14
15 View Code Duplication
    public function testRemoveFromArrayByIndex()
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
        ArrayUtils::removeByIndex($this->array, 0);
18
        $this->assertEquals(6, count($this->array));
19
        $this->assertEquals(array("bunch", "of", "words", "in", "an", "array"), $this->array);
20
21
        ArrayUtils::removeByIndex($this->array, 2);
22
        $this->assertEquals(5, count($this->array));
23
        $this->assertEquals(array("bunch", "of", "in", "an", "array"), $this->array);
24
    }
25
26
    public function testGetElementOnRemoveByIndex()
27
    {
28
        $this->assertEquals("a", ArrayUtils::removeByIndex($this->array, 0));
29
        $this->assertEquals("bunch", ArrayUtils::removeByIndex($this->array, 0));
30
        $this->assertEquals("of", ArrayUtils::removeByIndex($this->array, 0));
31
    }
32
33 View Code Duplication
    public function testRemoveFromArray()
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...
34
    {
35
        ArrayUtils::remove($this->array, "a");
36
        $this->assertEquals(6, count($this->array));
37
        $this->assertEquals(array("bunch", "of", "words", "in", "an", "array"), $this->array);
38
39
        ArrayUtils::remove($this->array, "words");
40
        $this->assertEquals(5, count($this->array));
41
        $this->assertEquals(array("bunch", "of", "in", "an", "array"), $this->array);
42
    }
43
44
}
45