Completed
Push — master ( b579d6...72e21a )
by Hector
11:54
created

Feature::assureApi()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 4
nop 1
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: hborras
5
 * Date: 11/01/18
6
 * Time: 20:06
7
 */
8
9
namespace Hborras\TwitterAdsSDK\TwitterAds\Campaign;
10
11
12
use Hborras\TwitterAdsSDK\TwitterAds;
13
use Hborras\TwitterAdsSDK\TwitterAds\Cursor;
14
15
class Feature
16
{
17
18
    const RESOURCE_COLLECTION = 'features';
19
    const RESOURCE_REPLACE    = '{account_id}';
20
21
    /** @var  TwitterAds $twitterAds */
22
    private $twitterAds;
23
24
    /**
25
     * Feature constructor.
26
     * @param TwitterAds $twitterAds
27
     */
28
    public function __construct(TwitterAds $twitterAds)
29
    {
30
31
        $this->twitterAds = static::assureApi($twitterAds);
32
    }
33
34 View Code Duplication
    protected static function assureApi(TwitterAds $instance = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36
        $instance = $instance ?: TwitterAds::instance();
37
        if (!$instance) {
38
            throw new \InvalidArgumentException(
39
                'An Api instance must be provided as argument or ' .
40
                'set as instance in the \TwitterAds\Api');
41
        }
42
        return $instance;
43
    }
44
45
    /**
46
     * Returns a Cursor instance for a given resource.
47
     *
48
     * @param $params
49
     *
50
     * @return Cursor
51
     */
52 View Code Duplication
    public function all($params = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        $resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE_COLLECTION);
55
        $response = $this->getTwitterAds()->get($resource, $params);
56
57
        return new Cursor($response->getBody()->data, $this->getTwitterAds(), $response->getBody(), $params);
58
    }
59
60
    /**
61
     * @return TwitterAds
62
     */
63
    public function getTwitterAds()
64
    {
65
        return $this->twitterAds;
66
    }
67
}