Completed
Push — master ( a39232...7f9bba )
by Sergey
03:07 queued 50s
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
     * Parse bookmarks from response.
24
     *
25
     * @return array
26
     */
27
    public function getBookmarks()
28
    {
29
        $searchBookmarks = $this
30
            ->response
31
            ->getData('module.tree.resource.options.bookmarks', []);
32
33
        return $searchBookmarks ? [$searchBookmarks[0]] : $this->response->getBookmarks();
34
    }
35
36
    /**
37
     * @return array
38
     */
39
    public function getResponseData()
40
    {
41
        $results = $this
42
            ->response
43
            ->getData('module.tree.data.results', []);
44
45
        return $results ? : $this->response->getResponseData();
46
    }
47
48
    /**
49
     * @return bool
50
     */
51
    public function isEmpty()
52
    {
53
        return empty($this->getResponseData());
54
    }
55
}