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

Feature   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 32.08 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 17
loc 53
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A assureApi() 10 10 3
A all() 7 7 1
A getTwitterAds() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}