Completed
Push — master ( 87209a...672fdc )
by Sergey
01:08
created

SearchResponse   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 2 Features 1
Metric Value
c 3
b 2
f 1
dl 0
loc 50
wmc 7
lcom 1
cbo 1
rs 10

4 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
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
    public function __construct(Response $response)
15
    {
16
        $this->response = $response;
17
    }
18
19
    /**
20
     * @return bool
21
     */
22
    public function hasResponseData()
23
    {
24
        $searchResults = $this
25
            ->response
26
            ->getData('module.tree.data.results', []);
27
28
        return $searchResults ? : $this->response->hasResponseData();
29
    }
30
31
    /**
32
     * Parse bookmarks from response.
33
     *
34
     * @return array
35
     */
36
    public function getBookmarks()
37
    {
38
        $searchBookmarks = $this
39
            ->response
40
            ->getData('module.tree.resource.options.bookmarks', []);
41
42
        return $searchBookmarks ? [$searchBookmarks[0]] : $this->response->getBookmarks();
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getResponseData()
49
    {
50
        $results = $this
51
            ->response
52
            ->getData('module.tree.data.results', []);
53
54
        return $results ? : $this->response->getResponseData();
55
    }
56
}