Completed
Pull Request — master (#223)
by Sergey
02:23
created

SearchResponse   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 49
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
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
     * 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
}