Completed
Push — master ( c13142...c0435c )
by Tobias
02:34
created

AutomaticCollection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 41.67%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 41
loc 41
ccs 5
cts 12
cp 0.4167
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 12 12 3
A createFromArray() 8 8 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
declare(strict_types=1);
4
5
namespace Billogram\Model\Invoice;
6
7
use Billogram\Model\CreatableFromArray;
8
9
/**
10
 * @author Ibrahim Hizeoui <[email protected]>
11
 */
12 View Code Duplication
class AutomaticCollection implements CreatableFromArray
0 ignored issues
show
Duplication introduced by
This class 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...
13
{
14
    /**
15
     * @var int
16
     */
17
    private $delayDays;
18
19
    /**
20
     * @var int
21
     */
22
    private $amount;
23
24
    public function toArray()
25
    {
26
        $data = [];
27
        if ($this->delayDays !== null) {
28
            $data['delay_days'] = $this->delayDays;
29
        }
30
        if ($this->amount !== null) {
31
            $data['message'] = $this->amount;
32
        }
33
34
        return $data;
35
    }
36
37
    /**
38
     * Create an API response object from the HTTP response from the API server.
39
     *
40
     * @param array $data
41
     *
42
     * @return self
43
     */
44 3
    public static function createFromArray(array $data)
45
    {
46 3
        $automaticReminder = new self();
47 3
        $automaticReminder->delayDays = $data['delay_days'];
48 3
        $automaticReminder->amount = $data['amount'];
49
50 3
        return $automaticReminder;
51
    }
52
}
53