Issues (16)

src/Search/Sort/ScoreSort.php (1 issue)

1
<?php namespace Nord\Lumen\Elasticsearch\Search\Sort;
2
3
/**
4
 * Allows to add one or more sort on specific fields. Each sort can be reversed as well. The sort is defined on a per
5
 * field level, with special field name for _score to sort by score, and _doc to sort by index order.
6
 *
7
 * The order defaults to desc when sorting on the _score, and defaults to asc when sorting on anything else.
8
 *
9
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html
10
 */
11
class ScoreSort extends AbstractSort
12
{
13
    /**
14
     * @inheritdoc
15
     */
16
    public function toArray()
17
    {
18
        $options = $this->applyOptions([]);
19
20
        if (empty($options)) {
21
            return '_score';
0 ignored issues
show
Bug Best Practice introduced by
The expression return '_score' returns the type string which is incompatible with the return type mandated by Illuminate\Contracts\Support\Arrayable::toArray() of array.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
22
        } else {
23
            return ['_score' => $options];
24
        }
25
    }
26
}
27