Completed
Pull Request — master (#221)
by Sergey
02:28
created

SearchResponse::getBookmarks()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace seregazhuk\PinterestBot\Api;
4
5
use seregazhuk\PinterestBot\Api\Contracts\PaginatedResponse;
6
7
class SearchResponse implements PaginatedResponse
8
{
9
    /**
10
     * @var Response
11
     */
12
    protected $response;
13
14
    /**
15
     * @param Response $response
16
     */
17
    public function __construct(Response $response)
18
    {
19
        $this->response = $response;
20
    }
21
22
    /**
23
     * @return bool
24
     */
25
    public function hasResponseData()
26
    {
27
        $searchResults = $this
28
            ->response
29
            ->getData('module.tree.data.results', []);
30
31
        return $searchResults ? : $this->response->hasResponseData();
32
    }
33
34
    /**
35
     * Parse bookmarks from response.
36
     *
37
     * @return array
38
     */
39
    public function getBookmarks()
40
    {
41
        $searchBookmarks = $this
42
            ->response
43
            ->getData('module.tree.resource.options.bookmarks', []);
44
45
        return $searchBookmarks ? [$searchBookmarks[0]] : $this->response->getBookmarks();
46
    }
47
48
    /**
49
     * @return array
50
     */
51
    public function getResponseData()
52
    {
53
        $results = $this
54
            ->response
55
            ->getData('module.tree.data.results', []);
56
57
        return $results ? : $this->response->getResponseData();
58
    }
59
60
    /**
61
     * @return bool
62
     */
63
    public function isEmpty()
64
    {
65
        return empty($this->getResponseData());
66
    }
67
}