TransfersList   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 21.82 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 12
loc 55
rs 10
c 2
b 0
f 0
wmc 4
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 5 1
A getTransfers() 0 4 1
A get() 0 4 1
A populate() 12 12 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
namespace Moip\Resource;
4
5
use Moip\Helper\Filters;
6
use Moip\Helper\Pagination;
7
use stdClass;
8
9
class TransfersList extends MoipResource
10
{
11
    /**
12
     * Path bank accounts API.
13
     *
14
     * @const string
15
     */
16
    const PATH = 'transfers';
17
18
    /**
19
     * Initialize a new instance.
20
     */
21
    public function initialize()
22
    {
23
        $this->data = new stdClass();
24
        $this->data->transfers = [];
25
    }
26
27
    /**
28
     * Get transfers.
29
     *
30
     * @return array
31
     */
32
    public function getTransfers()
33
    {
34
        return $this->getIfSet('transfers');
35
    }
36
37
    /**
38
     * Get transfer list.
39
     *
40
     * @param Pagination $pagination
41
     * @param Filters    $filters
42
     * @param string     $qParam     Query a specific value.
43
     *
44
     * @return stdClass
45
     */
46
    public function get(Pagination $pagination = null, Filters $filters = null, $qParam = '')
47
    {
48
        return $this->getByPath($this->generateListPath($pagination, $filters, ['q' => $qParam]));
49
    }
50
51 View Code Duplication
    protected function populate(stdClass $response)
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...
52
    {
53
        $transfersList = clone $this;
54
        $transfersList->data = new stdClass();
55
56
        $transfersList->data->transfers = $response->transfers;
57
58
        $transfersList->data->summary = $response->summary;
59
        $transfersList->_links = $response->_links;
0 ignored issues
show
Bug introduced by
The property _links 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...
60
61
        return $transfersList;
62
    }
63
}
64