Completed
Push — master ( d31412...ff3c6b )
by Sergey
05:01 queued 01:33
created

HasFollowers::getFollowData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
1
<?php
2
3
namespace seregazhuk\PinterestBot\Api\Traits;
4
5
use Iterator;
6
use seregazhuk\PinterestBot\Helpers\Pagination;
7
8
/**
9
 * Class HasFollowers
10
 * @package seregazhuk\PinterestBot\Api\Traits
11
 *
12
 * @property string $followersUrl
13
 * @property string $followersFor
14
 */
15
trait HasFollowers
16
{
17
    /**
18
     * Get followers.
19
     *
20
     * @param string $for
21
     * @param int $limit
22
     *
23
     * @return Iterator
24
     */
25
    public function followers($for, $limit = 0)
26
    {
27
        return $this->getFollowData(
28
            [$this->getFollowersFor() => $for], $this->getFollowersUrl(), $limit
29
        );
30
    }
31
    
32
    /**
33
     * @param array  $data
34
     * @param string $resourceUrl
35
     * @param int $limit
36
     *
37
     * @return Iterator
38
     */
39
    public function getFollowData($data, $resourceUrl, $limit = 0)
40
    {
41
        $requestData = array_merge([$data, $resourceUrl]);
42
43
        return (new Pagination($this))->paginateOver('getPaginatedData', $requestData, $limit);
44
    }
45
46
    protected function getFollowersUrl()
47
    {
48
        return property_exists($this, 'followersUrl') ? $this->followersUrl : '';
49
    }
50
51
    protected function getFollowersFor()
52
    {
53
        return property_exists($this, 'followersFor') ? $this->followersFor : '';
54
    }
55
}
56