Search::getNextPage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Clarify;
4
5
/**
6
 * Class Search
7
 * @package Clarify
8
 *
9
 * @deprecated since 1.3 Use \Clarify\Bundle->search() instead
10
 */
11
class Search extends Client
12
{
13
    public $detail = null;
14
15
    /**
16
     * @param $query
17
     * @param int $limit
18
     * @param array $params
19
     * @return array|bool|float|int|string
20
     */
21
    public function search($query, $limit = 10, $params = array())
22
    {
23
        $params['query'] = urlencode($query);
24
        $params['limit'] = (int) $limit;
25
26
        return $this->get('search', $params);
27
    }
28
29
    public function hasMorePages()
30
    {
31
        return isset($this->detail['_links']['next']);
32
    }
33
34
    public function getNextPage()
35
    {
36
        return $this->getPage('next');
37
    }
38
39
    public function getPreviousPage()
40
    {
41
        return $this->getPage('prev');
42
    }
43
44
    protected function getPage($direction = 'next')
45
    {
46
        if (isset($this->detail['_links'][$direction])) {
47
            $next_uri = $this->detail['_links'][$direction]['href'];
48
            $this->detail = $this->client->get($next_uri);
49
        } else {
50
            $this->detail = json_encode(array());
51
        }
52
53
        return $this->detail;
54
    }
55
}
56