Completed
Push — master ( 39f008...94ed84 )
by Harry
02:05
created

OneOfFilterTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 60.56 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 6
c 2
b 1
f 0
lcom 1
cbo 3
dl 43
loc 71
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testInstanceOf() 0 5 1
A testSingleChildConstructorEqualsMatchesOne() 10 10 1
A testSingleChildAddedLaterEqualsMatchesOne() 9 9 1
A testMultipleChildrenWithDifferentPropertiesMatchesOne() 0 15 1
A testMultipleChildrenWithTheSamePropertyMatchesOne() 14 14 1
A testOneOfFilterCanBeInvoked() 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
namespace Graze\ArrayFilter\Test\Unit;
4
5
use Graze\ArrayFilter\ClosureFilter;
6
use Graze\ArrayFilter\OneOfFilter;
7
use Graze\ArrayFilter\Test\TestCase;
8
9
class OneOfFilterTest extends TestCase
10
{
11
    public function testInstanceOf()
12
    {
13
        $filter = new OneOfFilter();
14
        static::assertInstanceOf('Graze\ArrayFilter\ArrayFilterInterface', $filter);
15
    }
16
17 View Code Duplication
    public function testSingleChildConstructorEqualsMatchesOne()
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...
18
    {
19
        $filter = new OneOfFilter([
20
            new ClosureFilter('test', function ($actual) {
21
                return $actual == 'value';
22
            }),
23
        ]);
24
        static::assertTrue($filter->matches(['test' => 'value']));
25
        static::assertFalse($filter->matches(['test' => 'values']));
26
    }
27
28 View Code Duplication
    public function testSingleChildAddedLaterEqualsMatchesOne()
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...
29
    {
30
        $filter = new OneOfFilter();
31
        $filter->addFilter(new ClosureFilter('test', function ($actual) {
32
            return $actual == 'value';
33
        }));
34
        static::assertTrue($filter->matches(['test' => 'value']));
35
        static::assertFalse($filter->matches(['test' => 'values']));
36
    }
37
38
    public function testMultipleChildrenWithDifferentPropertiesMatchesOne()
39
    {
40
        $filter = new OneOfFilter([
41
            new ClosureFilter('test', function ($actual) {
42
                return $actual == 'value';
43
            }),
44
            new ClosureFilter('test2', function ($actual) {
45
                return $actual == 'value2';
46
            }),
47
        ]);
48
        static::assertTrue($filter->matches(['test' => 'value']));
49
        static::assertTrue($filter->matches(['test2' => 'value2']));
50
        static::assertTrue($filter->matches(['test' => 'values', 'test2' => 'value2']));
51
        static::assertFalse($filter->matches(['test' => 'values', 'test2' => 'value3']));
52
    }
53
54 View Code Duplication
    public function testMultipleChildrenWithTheSamePropertyMatchesOne()
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...
55
    {
56
        $filter = new OneOfFilter([
57
            new ClosureFilter('test', function ($actual) {
58
                return $actual == 'foo';
59
            }),
60
            new ClosureFilter('test', function ($actual) {
61
                return $actual == 'bar';
62
            }),
63
        ]);
64
        static::assertFalse($filter->matches(['test' => 'value']));
65
        static::assertTrue($filter->matches(['test' => 'foo']));
66
        static::assertTrue($filter->matches(['test' => 'bar']));
67
    }
68
69 View Code Duplication
    public function testOneOfFilterCanBeInvoked()
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...
70
    {
71
        $filter = new OneOfFilter([
72
            new ClosureFilter('test', function ($actual) {
73
                return $actual == 'value';
74
            }),
75
        ]);
76
        static::assertTrue(call_user_func($filter, ['test' => 'value']));
77
        static::assertFalse(call_user_func($filter, ['test' => 'values']));
78
    }
79
}
80