Completed
Pull Request — master (#64)
by Thibaud
03:11
created

SearchResultInfo::getFacets()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 4
nc 4
nop 0
1
<?php
2
3
namespace PhraseanetSDK\Search;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use PhraseanetSDK\Entity\QueryFacet;
7
use PhraseanetSDK\EntityManager;
8
9
class SearchResultInfo
10
{
11
    /**
12
     * @param EntityManager $entityManager
13
     * @param \stdClass $value
14
     * @return SearchResultInfo
15
     */
16
    public static function fromValue(EntityManager $entityManager, \stdClass $value)
17
    {
18
        return new self($entityManager, $value);
19
    }
20
21
    /**
22
     * @var EntityManager
23
     */
24
    protected $entityManager;
25
26
    /**
27
     * @var \stdClass
28
     */
29
    protected $source;
30
31
    /**
32
     * @var QueryFacet[]|ArrayCollection
33
     */
34
    protected $facets;
35
36
37
    /**
38
     * @param EntityManager $entityManager
39
     * @param \stdClass $source
40
     */
41
    public function __construct(EntityManager $entityManager, \stdClass $source)
42
    {
43
        $this->entityManager = $entityManager;
44
        $this->source = $source;
45
    }
46
47
    /**
48
     * The offset start
49
     *
50
     * @return integer
51
     */
52
    public function getOffsetStart()
53
    {
54
        return $this->source->offset_start;
55
    }
56
57
    /**
58
     * The number item to retrieve
59
     *
60
     * @return integer
61
     */
62
    public function getPerPage()
63
    {
64
        return $this->source->per_page;
65
    }
66
67
    /**
68
     * Get the total result
69
     *
70
     * @return integer
71
     */
72
    public function getTotalResults()
73
    {
74
        return $this->source->total_results;
75
    }
76
77
    /**
78
     * Get errors as string
79
     *
80
     * @return string
81
     */
82
    public function getError()
83
    {
84
        return $this->source->error;
85
    }
86
87
    /**
88
     * Get warnings as string
89
     *
90
     * @return string
91
     */
92
    public function getWarning()
93
    {
94
        return $this->source->warning;
95
    }
96
97
    /**
98
     * Get the query time
99
     *
100
     * @return float
101
     */
102
    public function getQueryTime()
103
    {
104
        return $this->source->query_time;
105
    }
106
107
    /**
108
     * Get search indexes
109
     *
110
     * @return string
111
     */
112
    public function getSearchIndexes()
113
    {
114
        return $this->source->search_indexes;
115
    }
116
117
    /**
118
     * Get the query string
119
     *
120
     * @return string
121
     */
122
    public function getQuery()
123
    {
124
        return $this->source->query;
125
    }
126
127
    /**
128
     * @return ArrayCollection|QueryFacet[]
129
     */
130
    public function getFacets()
131
    {
132
        if (! isset($this->source->facets)) {
133
            $this->facets = new ArrayCollection();
134
        }
135
136
        return $this->facets ?: $this->facets = new ArrayCollection(QueryFacet::fromList($this->source->facets));
137
    }
138
}
139