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

Followable   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 58
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A follow() 0 4 1
A unFollow() 0 4 1
A followCall() 0 6 1
A getFollowUrl() 0 4 2
A getUnFollowUrl() 0 4 2
1
<?php
2
3
namespace seregazhuk\PinterestBot\Api\Traits;
4
5
/**
6
 * Class Followable
7
 * @package seregazhuk\PinterestBot\Api\Traits
8
 *
9
 * @property string $followUrl
10
 * @property string $unFollowUrl
11
 */
12
trait Followable
13
{
14
    use HandlesRequestAndResponse, HasEntityIdName;
15
    /**
16
     * Follow user by user_id.
17
     *
18
     * @param $entityId
19
     *
20
     * @return bool
21
     */
22
    public function follow($entityId)
23
    {
24
        return $this->followCall($entityId, $this->getFollowUrl());
25
    }
26
27
    /**
28
     * UnFollow user by user_id.
29
     *
30
     * @param $entityId
31
     *
32
     * @return bool
33
     */
34
    public function unFollow($entityId)
35
    {
36
        return $this->followCall($entityId, $this->getUnFollowUrl());
37
    }
38
39
    /**
40
     * Make api call for follow/unFollow a entity (user/board).
41
     *
42
     * @param int    $entityId
43
     * @param string $resourceUrl
44
     *
45
     * @return bool
46
     */
47
    protected function followCall($entityId, $resourceUrl)
48
    {
49
        $response = $this->getRequest()->followMethodCall($entityId, $this->getEntityIdName(), $resourceUrl);
50
51
        return $this->getResponse()->hasErrors($response);
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    protected function getFollowUrl()
58
    {
59
        return property_exists($this, 'followUrl') ? $this->followUrl : '';
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    protected function getUnFollowUrl()
66
    {
67
        return property_exists($this, 'followUrl') ? $this->unFollowUrl : '';
68
    }
69
}
70