AllOfFilterTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 81
Duplicated Lines 66.67 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 8
c 3
b 1
f 1
lcom 1
cbo 3
dl 54
loc 81
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testInstanceOf() 0 5 1
A testSingleChildConstructorEqualsMatchesAll() 10 10 1
A testSingleChildAddedLaterEqualsMatchesAll() 9 9 1
A testMultipleChildrenWithDifferentPropertiesMatchesAll() 0 13 1
A testMultipleChildrenWithTheSamePropertyMatchesAll() 14 14 1
A testAllOfFilterCanBeInvoked() 10 10 1
A testCallableFiltersMatchesAll() 11 11 2

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
 * This file is part of graze/array-filter
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/array-filter/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/array-filter
12
 */
13
14
namespace Graze\ArrayFilter\Test\Unit;
15
16
use Graze\ArrayFilter\AllOfFilter;
17
use Graze\ArrayFilter\ClosureFilter;
18
use Graze\ArrayFilter\Test\TestCase;
19
20
class AllOfFilterTest extends TestCase
21
{
22
    public function testInstanceOf()
23
    {
24
        $filter = new AllOfFilter();
25
        static::assertInstanceOf('Graze\ArrayFilter\ArrayFilterInterface', $filter);
26
    }
27
28 View Code Duplication
    public function testSingleChildConstructorEqualsMatchesAll()
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 AllOfFilter([
31
            new ClosureFilter('test', function ($actual) {
32
                return $actual == 'value';
33
            }),
34
        ]);
35
        static::assertTrue($filter->matches(['test' => 'value']));
36
        static::assertFalse($filter->matches(['test' => 'values']));
37
    }
38
39 View Code Duplication
    public function testSingleChildAddedLaterEqualsMatchesAll()
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...
40
    {
41
        $filter = new AllOfFilter();
42
        $filter->addFilter(new ClosureFilter('test', function ($actual) {
43
            return $actual == 'value';
44
        }));
45
        static::assertTrue($filter->matches(['test' => 'value']));
46
        static::assertFalse($filter->matches(['test' => 'values']));
47
    }
48
49
    public function testMultipleChildrenWithDifferentPropertiesMatchesAll()
50
    {
51
        $filter = new AllOfFilter([
52
            new ClosureFilter('test', function ($actual) {
53
                return $actual == 'value';
54
            }),
55
            new ClosureFilter('test2', function ($actual) {
56
                return $actual == 'value2';
57
            }),
58
        ]);
59
        static::assertTrue($filter->matches(['test' => 'value', 'test2' => 'value2']));
60
        static::assertFalse($filter->matches(['test' => 'values', 'test2' => 'value2']));
61
    }
62
63 View Code Duplication
    public function testMultipleChildrenWithTheSamePropertyMatchesAll()
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...
64
    {
65
        $filter = new AllOfFilter([
66
            new ClosureFilter('test', function ($actual) {
67
                return $actual != 'foo';
68
            }),
69
            new ClosureFilter('test', function ($actual) {
70
                return $actual != 'bar';
71
            }),
72
        ]);
73
        static::assertTrue($filter->matches(['test' => 'value']));
74
        static::assertFalse($filter->matches(['test' => 'foo']));
75
        static::assertFalse($filter->matches(['test' => 'bar']));
76
    }
77
78 View Code Duplication
    public function testCallableFiltersMatchesAll()
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
        $filter = new AllOfFilter([
81
            function (array $data) {
82
                return isset($data['test']) && $data['test'] == 'value';
83
            }
84
        ]);
85
        static::assertTrue($filter(['test' => 'value']));
86
        static::assertFalse($filter(['test' => 'values']));
87
        static::assertFalse($filter(['tests' => 'values']));
88
    }
89
90 View Code Duplication
    public function testAllOfFilterCanBeInvoked()
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...
91
    {
92
        $filter = new AllOfFilter([
93
            new ClosureFilter('test', function ($actual) {
94
                return $actual == 'value';
95
            }),
96
        ]);
97
        static::assertTrue(call_user_func($filter, ['test' => 'value']));
98
        static::assertFalse(call_user_func($filter, ['test' => 'values']));
99
    }
100
}
101