Completed
Pull Request — master (#76)
by Chad
07:21
created

ArraysTest   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 112
Duplicated Lines 16.07 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 3
dl 18
loc 112
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A filterBasicPass() 0 4 1
A filterFailNotArray() 0 4 1
A filterFailEmpty() 0 4 1
A filterCountLessThanMin() 0 4 1
A filterCountGreaterThanMax() 0 4 1
A inPassStrict() 0 4 1
A inFailStrict() 9 9 2
A inFailNotStrict() 9 9 2
A inPassNotStrict() 0 4 1
A flatten() 0 4 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 TraderInteractive\Filter;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * @coversDefaultClass \TraderInteractive\Filter\Arrays
9
 */
10
final class ArraysTest extends TestCase
11
{
12
    /**
13
     * @test
14
     * @covers ::filter
15
     */
16
    public function filterBasicPass()
17
    {
18
        $this->assertSame(['boo'], Arrays::filter(['boo']));
19
    }
20
21
    /**
22
     * @test
23
     * @covers ::filter
24
     * @expectedException \TraderInteractive\Filter\Exception
25
     * @expectedExceptionMessage Value '1' is not an array
26
     */
27
    public function filterFailNotArray()
28
    {
29
        Arrays::filter(1);
30
    }
31
32
    /**
33
     * @test
34
     * @covers ::filter
35
     * @expectedException \TraderInteractive\Filter\Exception
36
     * @expectedExceptionMessage $value count of 0 is less than 1
37
     */
38
    public function filterFailEmpty()
39
    {
40
        Arrays::filter([]);
41
    }
42
43
    /**
44
     * @test
45
     * @covers ::filter
46
     * @expectedException \TraderInteractive\Filter\Exception
47
     * @expectedExceptionMessage $value count of 1 is less than 2
48
     */
49
    public function filterCountLessThanMin()
50
    {
51
        Arrays::filter([0], 2);
52
    }
53
54
    /**
55
     * @test
56
     * @covers ::filter
57
     * @expectedException \TraderInteractive\Filter\Exception
58
     * @expectedExceptionMessage $value count of 2 is greater than 1
59
     */
60
    public function filterCountGreaterThanMax()
61
    {
62
        Arrays::filter([0, 1], 1, 1);
63
    }
64
65
    /**
66
     * @test
67
     * @covers ::in
68
     */
69
    public function inPassStrict()
70
    {
71
        $this->assertSame('boo', Arrays::in('boo', ['boo']));
72
    }
73
74
    /**
75
     * @test
76
     * @covers ::in
77
     */
78 View Code Duplication
    public function inFailStrict()
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...
79
    {
80
        try {
81
            Arrays::in('0', [0]);
82
            $this->fail();
83
        } catch (Exception $e) {
84
            $this->assertSame("Value '0' is not in array array (\n  0 => 0,\n)", $e->getMessage());
85
        }
86
    }
87
88
    /**
89
     * @test
90
     * @covers ::in
91
     */
92 View Code Duplication
    public function inFailNotStrict()
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...
93
    {
94
        try {
95
            Arrays::in('boo', ['foo'], false);
96
            $this->fail();
97
        } catch (Exception $e) {
98
            $this->assertSame("Value 'boo' is not in array array (\n  0 => 'foo',\n)", $e->getMessage());
99
        }
100
    }
101
102
    /**
103
     * @test
104
     * @covers ::in
105
     */
106
    public function inPassNotStrict()
107
    {
108
        $this->assertSame('0', Arrays::in('0', [0], false));
109
    }
110
111
    /**
112
     * Verifies the basic behavior of the flatten filter.
113
     *
114
     * @test
115
     * @covers ::flatten
116
     */
117
    public function flatten()
118
    {
119
        $this->assertSame([1, 2, 3, 4, 5], Arrays::flatten([[1, 2], [[3, [4, 5]]]]));
120
    }
121
}
122