Completed
Push — 2.1 ( d7139b...4f94f6 )
by Rafał
09:57
created

AuthorRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 7
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A findByCriteria() 0 22 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher ElasticSearch Bundle.
7
 *
8
 * Copyright 2017 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2017 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\ElasticSearchBundle\Repository;
18
19
use Elastica\Query;
20
use Elastica\Query\BoolQuery;
21
use Elastica\Query\MatchAll;
22
use FOS\ElasticaBundle\Paginator\PaginatorAdapterInterface;
23
use FOS\ElasticaBundle\Repository;
24
use SWP\Bundle\ElasticSearchBundle\Criteria\Criteria;
25
26
class AuthorRepository extends Repository
27
{
28
    public function findByCriteria(Criteria $criteria): PaginatorAdapterInterface
29
    {
30
        $boolFilter = new BoolQuery();
31
32
        if (null !== $criteria->getTerm() && '' !== $criteria->getTerm()) {
33
            $boolQuery = new BoolQuery();
34
            $term = $criteria->getTerm();
35
36
            $boolQuery->addShould(new Query\MatchPhrase('name', $term));
37
            $boolFilter->addMust($boolQuery);
38
        } else {
39
            $boolFilter->addMust(new MatchAll());
40
        }
41
42
        $query = Query::create($boolFilter)
43
            ->addSort([
44
                '_score' => 'desc',
45
                $criteria->getOrder()->getField() => $criteria->getOrder()->getDirection(),
46
            ]);
47
48
        return $this->createPaginatorAdapter($query);
0 ignored issues
show
Documentation introduced by
$query is of type object<Elastica\Query>, but the function expects a string.

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...
49
    }
50
}
51