Completed
Pull Request — master (#1911)
by Sam
03:08
created

PostFilterTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 49.06 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 26
loc 53
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A _getTestIndex() 14 14 1
A testToArray() 12 12 1
A testQuery() 0 16 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 Elastica\Test\Query;
4
5
use Elastica\Document;
6
use Elastica\Query;
7
use Elastica\Query\MatchQuery;
8
use Elastica\Query\Term;
9
use Elastica\Test\Base as BaseTest;
10
11
/**
12
 * @internal
13
 */
14
class PostFilterTest extends BaseTest
15
{
16
    /**
17
     * @group unit
18
     */
19 View Code Duplication
    public function testToArray(): void
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...
20
    {
21
        $query = new Query();
22
23
        $postFilter = new Term(['color' => 'green']);
24
        $query->setPostFilter($postFilter);
25
26
        $data = $query->toArray();
27
28
        $this->assertArrayHasKey('post_filter', $data);
29
        $this->assertEquals(['term' => ['color' => 'green']], $data['post_filter']);
30
    }
31
32
    /**
33
     * @group functional
34
     */
35
    public function testQuery(): void
36
    {
37
        $query = new Query();
38
39
        $match = new MatchQuery();
40
        $match->setField('make', 'ford');
41
42
        $query->setQuery($match);
43
44
        $filter = new Term();
45
        $filter->setTerm('color', 'green');
46
47
        $query->setPostFilter($filter);
48
49
        $this->assertEquals(1, $this->_getTestIndex()->count($query));
50
    }
51
52 View Code Duplication
    protected function _getTestIndex()
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...
53
    {
54
        $index = $this->_createIndex();
55
        $docs = [
56
            new Document(1, ['color' => 'green', 'make' => 'ford']),
57
            new Document(2, ['color' => 'blue', 'make' => 'volvo']),
58
            new Document(3, ['color' => 'red', 'make' => 'ford']),
59
            new Document(4, ['color' => 'green', 'make' => 'renault']),
60
        ];
61
        $index->addDocuments($docs);
62
        $index->refresh();
63
64
        return $index;
65
    }
66
}
67