Search   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 11
Bugs 0 Features 1
Metric Value
wmc 6
c 11
b 0
f 1
lcom 1
cbo 2
dl 0
loc 45
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasMorePages() 0 4 1
A getNextPage() 0 4 1
A getPreviousPage() 0 4 1
A search() 0 7 1
A getPage() 0 11 2
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