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

SearchResponse   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 61
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A hasResponseData() 0 8 2
A getBookmarks() 0 8 2
A getResponseData() 0 8 2
A isEmpty() 0 4 1
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
}