Completed
Push — master ( d3ac62...0cb203 )
by Federico
02:08
created

lib/Elastica/Query/Range.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Elastica\Query;
4
5
/**
6
 * Range query.
7
 *
8
 * @author Nicolas Ruflin <[email protected]>
9
 *
10
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html
11
 */
12
class Range extends AbstractQuery
13
{
14
    /**
15
     * Constructor.
16
     *
17
     * @param string $fieldName Field name
18
     * @param array  $args      Field arguments
19
     */
20
    public function __construct($fieldName = null, array $args = [])
21
    {
22
        if ($fieldName) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $fieldName of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
23
            $this->addField($fieldName, $args);
24
        }
25
    }
26
27
    /**
28
     * Adds a range field to the query.
29
     *
30
     * @param string $fieldName Field name
31
     * @param array  $args      Field arguments
32
     *
33
     * @return $this
34
     */
35
    public function addField($fieldName, array $args)
36
    {
37
        return $this->setParam($fieldName, $args);
38
    }
39
}
40