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

lib/Elastica/Query/Type.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
 * Type Query.
7
 *
8
 * @author James Wilson <[email protected]>
9
 *
10
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-type-query.html
11
 */
12
class Type extends AbstractQuery
13
{
14
    /**
15
     * Type name.
16
     *
17
     * @var string
18
     */
19
    protected $_type;
20
21
    /**
22
     * Construct Type Query.
23
     *
24
     * @param string $type Type name
25
     */
26
    public function __construct($type = null)
27
    {
28
        if ($type) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $type 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...
29
            $this->setType($type);
30
        }
31
    }
32
33
    /**
34
     * Ads a field with arguments to the range query.
35
     *
36
     * @param string $typeName Type name
37
     *
38
     * @return $this
39
     */
40
    public function setType($typeName)
41
    {
42
        $this->_type = $typeName;
43
44
        return $this;
45
    }
46
47
    /**
48
     * Convert object to array.
49
     *
50
     * @see \Elastica\Query\AbstractQuery::toArray()
51
     *
52
     * @return array Query array
53
     */
54
    public function toArray()
55
    {
56
        return [
57
            'type' => ['value' => $this->_type],
58
        ];
59
    }
60
}
61