Completed
Push — master ( 874d6a...5decb7 )
by Thibaud
10s
created

Query::getOffsetStart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of Phraseanet SDK.
5
 *
6
 * (c) Alchemy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhraseanetSDK\Entity;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use PhraseanetSDK\Annotation\ApiField as ApiField;
16
use PhraseanetSDK\Annotation\ApiRelation as ApiRelation;
17
use PhraseanetSDK\EntityManager;
18
19
class Query
20
{
21
22
    /**
23
     * @param EntityManager $entityManager
24
     * @param \stdClass $value
25
     * @return Query
26
     */
27 3
    public static function fromValue(EntityManager $entityManager, \stdClass $value)
28
    {
29 3
        return new self($entityManager, $value);
30
    }
31
32
    /**
33
     * @var EntityManager
34
     */
35
    protected $entityManager;
36
37
    /**
38
     * @var \stdClass
39
     */
40
    protected $source;
41
42
    /**
43
     * @var QueryFacet[]|ArrayCollection
44
     */
45
    protected $facets;
46
47
    /**
48
     * @var QuerySuggestion[]|ArrayCollection
49
     */
50
    protected $suggestions;
51
52
    /**
53
     * @var Result|null
54
     */
55
    protected $results;
56
57
    /**
58
     * @param EntityManager $entityManager
59
     * @param \stdClass $source
60
     */
61 3
    public function __construct(EntityManager $entityManager, \stdClass $source)
62
    {
63 3
        $this->entityManager = $entityManager;
64 3
        $this->source = $source;
65 3
    }
66
67
    /**
68
     * @return \stdClass
69
     */
70
    public function getRawData()
71
    {
72 1
        return $this->source;
73
    }
74 1
75
    /**
76
     * The offset start
77
     *
78
     * @return integer
79
     */
80
    public function getOffsetStart()
81
    {
82 1
        return $this->source->offset_start;
83
    }
84 1
85
    /**
86
     * The number item to retrieve
87
     *
88
     * @return integer
89
     */
90
    public function getPerPage()
91
    {
92 1
        return $this->source->per_page;
93
    }
94 1
95
    /**
96
     * Get the total result
97
     *
98
     * @return integer
99
     */
100
    public function getTotalResults()
101
    {
102 1
        return $this->source->total_results;
103
    }
104 1
105
    /**
106
     * Get errors as string
107
     *
108
     * @return string
109
     */
110
    public function getError()
111
    {
112 1
        return $this->source->error;
113
    }
114 1
115
    /**
116
     * Get warnings as string
117
     *
118
     * @return string
119
     */
120
    public function getWarning()
121
    {
122 1
        return $this->source->warning;
123
    }
124 1
125
    /**
126
     * Get the query time
127
     *
128
     * @return float
129
     */
130
    public function getQueryTime()
131
    {
132 1
        return $this->source->query_time;
133
    }
134 1
135
    /**
136
     * Get search indexes
137
     *
138
     * @return string
139
     */
140
    public function getSearchIndexes()
141
    {
142 1
        return $this->source->search_indexes;
143
    }
144 1
145
    /**
146
     * Get the query string
147
     *
148
     * @return string
149
     */
150
    public function getQuery()
151
    {
152
        return $this->source->query;
153 1
    }
154
155 1
    /**
156
     * Get query suggestions as a collection of QuerySuggestion
157
     * objects
158
     *
159 1
     * @return ArrayCollection
160 1
     */
161 1
    public function getSuggestions()
162
    {
163
        if (! isset($this->source->suggestions)) {
164
            $this->suggestions = new ArrayCollection();
165
        }
166
167
        return $this->suggestions ?: $this->suggestions = new ArrayCollection(QuerySuggestion::fromList(
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->suggestions ?: ($...source->suggestions))); of type PhraseanetSDK\Entity\Que...ections\ArrayCollection adds the type PhraseanetSDK\Entity\QuerySuggestion[] to the return on line 167 which is incompatible with the return type documented by PhraseanetSDK\Entity\Query::getSuggestions of type Doctrine\Common\Collections\ArrayCollection.
Loading history...
168
            $this->source->suggestions
169
        ));
170
    }
171
172
    /**
173
     * @return ArrayCollection|QueryFacet[]
174
     */
175
    public function getFacets()
176
    {
177
        if (! isset($this->source->facets)) {
178
            $this->facets = new ArrayCollection();
179
        }
180 3
181
        return $this->facets ?: $this->facets = new ArrayCollection(QueryFacet::fromList($this->source->facets));
182 3
    }
183
184
    /**
185
     *
186
     * @return Result
187
     */
188
    public function getResults()
189
    {
190
        return $this->results ?: $this->results = Result::fromValue($this->entityManager, $this->source->results);
191
    }
192
}
193