ClosureFilterTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 8
loc 36
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testInstanceOf() 0 7 1
A testBasicEquals() 8 8 1
A testReturnsFalseWhenInvalidPropertySpecified() 0 7 1
A testClosureFilterCanBeInvoked() 0 8 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
 * 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\ClosureFilter;
17
use Graze\ArrayFilter\Test\TestCase;
18
19
class ClosureFilterTest extends TestCase
20
{
21
    public function testInstanceOf()
22
    {
23
        $filter = new ClosureFilter('', function ($actual) {
24
            return $actual == 'value';
25
        });
26
        static::assertInstanceOf('Graze\ArrayFilter\ArrayFilterInterface', $filter);
27
    }
28
29 View Code Duplication
    public function testBasicEquals()
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...
30
    {
31
        $filter = 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 testReturnsFalseWhenInvalidPropertySpecified()
39
    {
40
        $filter = new ClosureFilter('invalid', function ($actual) {
41
            return $actual == 'value';
42
        });
43
        static::assertFalse($filter->matches(['invilad' => 'value']));
44
    }
45
46
    public function testClosureFilterCanBeInvoked()
47
    {
48
        $filter = new ClosureFilter('test', function ($actual) {
49
            return $actual == 'value';
50
        });
51
        static::assertTrue(call_user_func($filter, ['test' => 'value']));
52
        static::assertFalse(call_user_func($filter, ['test' => 'values']));
53
    }
54
}
55