Completed
Pull Request — master (#237)
by Sergey
02:43
created

Pinners::paginateByUsername()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
namespace seregazhuk\PinterestBot\Api\Providers;
4
5
use seregazhuk\PinterestBot\Api\Response;
6
use seregazhuk\PinterestBot\Helpers\Pagination;
7
use seregazhuk\PinterestBot\Helpers\UrlBuilder;
8
use seregazhuk\PinterestBot\Api\Traits\Followable;
9
use seregazhuk\PinterestBot\Api\Traits\Searchable;
10
use seregazhuk\PinterestBot\Exceptions\WrongFollowingType;
11
12
class Pinners extends EntityProvider
13
{
14
    use Searchable, Followable;
15
16
    /**
17
     * @var array
18
     */
19
    protected $loginRequiredFor = [
20
        'follow',
21
        'block',
22
        'unFollow',
23
        'blockById',
24
    ];
25
26
    protected $searchScope  = 'people';
27
    protected $entityIdName = 'user_id';
28
    protected $followersFor = 'username';
29
30
    protected $followUrl    = UrlBuilder::RESOURCE_FOLLOW_USER;
31
    protected $unFollowUrl  = UrlBuilder::RESOURCE_UNFOLLOW_USER;
32
    protected $followersUrl = UrlBuilder::RESOURCE_USER_FOLLOWERS;
33
    
34
    /**
35
     * Get user info.
36
     * If username param is not specified, will
37
     * return info for logged user.
38
     *
39
     * @param string $username
40
     * @return array
41
     */
42
    public function info($username)
43
    {
44
        return $this->execGetRequest(['username' => $username], UrlBuilder::RESOURCE_USER_INFO);
45
    }
46
47
    /**
48
     * Get following info for pinner.
49
     *
50
     * @param string $username
51
     * @param string $type
52
     * @param int $limit
53
     * @return Pagination
54
     * @throws WrongFollowingType
55
     */
56
    public function following($username, $type = UrlBuilder::FOLLOWING_PEOPLE, $limit = Pagination::DEFAULT_LIMIT)
57
    {
58
        $followingUrl = UrlBuilder::getFollowingUrlByType($type);
59
60
        if(empty($followingUrl)) {
61
            throw new WrongFollowingType("No following results for $type");
62
        }
63
64
        return $this->paginateByUsername($username, $followingUrl, $limit);
65
    }
66
67
    /**
68
     * @codeCoverageIgnore
69
     * Get following people for pinner.
70
     *
71
     * @param string $username
72
     * @param int $limit
73
     * @return Pagination
74
     */
75
    public function followingPeople($username, $limit = Pagination::DEFAULT_LIMIT)
76
    {
77
        return $this->following($username, UrlBuilder::FOLLOWING_PEOPLE, $limit);
78
    }
79
80
    /**
81
     * @codeCoverageIgnore
82
     * Get following boards for pinner.
83
     *
84
     * @param string $username
85
     * @param int $limit
86
     * @return Pagination
87
     */
88
    public function followingBoards($username, $limit = Pagination::DEFAULT_LIMIT)
89
    {
90
        return $this->following($username, UrlBuilder::FOLLOWING_BOARDS, $limit);
91
    }
92
93
    /**
94
     * @codeCoverageIgnore
95
     * Get following interests for pinner.
96
     *
97
     * @param string $username
98
     * @param int $limit
99
     * @return Pagination
100
     * @throws WrongFollowingType
101
     */
102
    public function followingInterests($username, $limit = Pagination::DEFAULT_LIMIT)
103
    {
104
        return $this->following($username, UrlBuilder::FOLLOWING_INTERESTS, $limit);
105
    }
106
107
    /**
108
     * Get pinner pins.
109
     *
110
     * @param string $username
111
     * @param int $limit
112
     *
113
     * @return Pagination
114
     */
115
    public function pins($username, $limit = Pagination::DEFAULT_LIMIT)
116
    {
117
        return $this->paginateByUsername(
118
            $username, UrlBuilder::RESOURCE_USER_PINS, $limit
119
        );
120
    }
121
122
    /**
123
     * Get pins that user likes.
124
     *
125
     * @param string $username
126
     * @param int $limit
127
     * @return Pagination
128
     */
129
    public function likes($username, $limit = Pagination::DEFAULT_LIMIT)
130
    {
131
        return $this->paginateByUsername(
132
            $username, UrlBuilder::RESOURCE_USER_LIKES, $limit
133
        );
134
    }
135
136
    /**
137
     * @param string $username
138
     * @return bool|Response
139
     */
140
    public function block($username)
141
    {
142
        // Retrieve profile data to get user id
143
        $profile = $this->info($username);
144
145
        if(empty($profile)) return false;
146
147
        return $this->blockById($profile['id']);
148
    }
149
150
    /**
151
     * @param int $userId
152
     * @return bool|Response
153
     */
154
    public function blockById($userId)
155
    {
156
        $data = ['blocked_user_id' => $userId];
157
158
        return $this->execPostRequest($data, UrlBuilder::RESOURCE_BLOCK_USER);
159
    }
160
161
    /**
162
     * @param string $username
163
     * @param string $url
164
     * @param int $limit
165
     *
166
     * @return Pagination
167
     */
168
    protected function paginateByUsername($username, $url, $limit = Pagination::DEFAULT_LIMIT)
169
    {
170
        return parent::paginate(['username' => $username], $url, $limit);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (paginate() instead of paginateByUsername()). Are you sure this is correct? If so, you might want to change this to $this->paginate().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
171
    }
172
}
173