Completed
Push — master ( cc9e5c...67ffd6 )
by Sergey
13:28 queued 10:12
created

Followable::getUnFollowUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
namespace seregazhuk\PinterestBot\Helpers\Providers\Traits;
4
5
trait Followable
6
{
7
    use HandlesRequestAndResponse, HasEntityIdName;
8
    /**
9
     * Follow user by user_id.
10
     *
11
     * @param $entityId
12
     *
13
     * @return bool
14
     */
15
    public function follow($entityId)
16
    {
17
        return $this->followCall($entityId, $this->getFollowUrl());
18
    }
19
20
    /**
21
     * UnFollow user by user_id.
22
     *
23
     * @param $entityId
24
     *
25
     * @return bool
26
     */
27
    public function unFollow($entityId)
28
    {
29
        return $this->followCall($entityId, $this->getUnFollowUrl());
30
    }
31
32
    /**
33
     * Make api call for follow/unFollow a entity (user/board).
34
     *
35
     * @param int    $entityId
36
     * @param string $resourceUrl
37
     *
38
     * @return bool
39
     */
40
    protected function followCall($entityId, $resourceUrl)
41
    {
42
        $response = $this->getRequest()->followMethodCall($entityId, $this->getEntityIdName(), $resourceUrl);
43
44
        return $this->getResponse()->hasErrors($response);
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    protected function getFollowUrl()
51
    {
52
        return property_exists($this, 'followUrl') ? $this->followUrl : '';
0 ignored issues
show
Bug introduced by
The property followUrl does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    protected function getUnFollowUrl()
59
    {
60
        return property_exists($this, 'followUrl') ? $this->unFollowUrl : '';
0 ignored issues
show
Bug introduced by
The property unFollowUrl does not seem to exist. Did you mean followUrl?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
61
    }
62
}
63