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

EscapeStringTest::testSearch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 20
Ratio 100 %

Importance

Changes 0
Metric Value
dl 20
loc 20
rs 9.6
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Elastica\Test\Query;
4
5
use Elastica\Document;
6
use Elastica\Query\QueryString;
7
use Elastica\Test\Base as BaseTest;
8
use Elastica\Util;
9
10
/**
11
 * @internal
12
 */
13
class EscapeStringTest extends BaseTest
14
{
15
    /**
16
     * @group functional
17
     */
18 View Code Duplication
    public function testSearch(): 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...
19
    {
20
        $index = $this->_createIndex();
21
        $index->getSettings()->setNumberOfReplicas(0);
22
23
        $doc = new Document(
24
            1,
25
            [
26
                'email' => '[email protected]', 'username' => 'test 7/6 123', 'test' => ['2', '3', '5'], ]
27
        );
28
        $index->addDocument($doc);
29
30
        // Refresh index
31
        $index->refresh();
32
33
        $queryString = new QueryString(Util::escapeTerm('test 7/6'));
34
        $resultSet = $index->search($queryString);
0 ignored issues
show
Documentation introduced by
$queryString is of type object<Elastica\Query\QueryString>, but the function expects a string|array|object<Elastica\Query>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
35
36
        $this->assertEquals(1, $resultSet->count());
37
    }
38
}
39