Completed
Pull Request — master (#182)
by Sergey
02:46
created

HasTopics   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 48
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRelatedTopics() 0 7 1
A getPinsFor() 0 9 1
getFeedRequestData() 0 1 ?
A getFeedUrl() 0 4 2
1
<?php
2
3
namespace seregazhuk\PinterestBot\Api\Traits;
4
5
use Generator;
6
use seregazhuk\PinterestBot\Helpers\UrlBuilder;
7
8
/**
9
 * Trait HasRelatedTopics
10
 * @package seregazhuk\PinterestBot\Api\Traits
11
 *
12
 * @property string $feedUrl
13
 */
14
trait HasTopics
15
{
16
    use HandlesRequest;
17
18
    /**
19
     * Returns a list of related topics
20
     * @param string $interest
21
     * @return array|bool
22
     */
23
    public function getRelatedTopics($interest)
24
    {
25
        return $this->execGetRequest(
26
            ['interest_name' => $interest],
27
            UrlBuilder::RESOURCE_GET_CATEGORIES_RELATED
28
        );
29
    }
30
31
    /**
32
     * Returns a feed of pins.
33
     *
34
     * @param string $interest
35
     * @param int $limit
36
     * @return Generator
37
     */
38
    public function getPinsFor($interest, $limit = 0)
39
    {
40
        $params = [
41
            'data' => $this->getFeedRequestData($interest),
42
            'url'  => $this->getFeedUrl(),
43
        ];
44
45
        return $this->getPaginatedResponse($params, $limit);
0 ignored issues
show
Bug introduced by
It seems like getPaginatedResponse() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
46
    }
47
48
    /**
49
     * @param $interest
50
     * @return array
51
     */
52
    abstract protected function getFeedRequestData($interest);
53
54
    /**
55
     * @return string
56
     */
57
    protected function getFeedUrl()
58
    {
59
        return property_exists($this, 'feedUrl') ? $this->feedUrl : '';
60
    }
61
}