Completed
Push — master ( a5de38...845fca )
by Andrii
06:07
created

Sale   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 29.87 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 23
loc 77
ccs 0
cts 43
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 13 13 1
A getId() 0 4 1
A getTarget() 0 4 1
A getCustomer() 0 4 1
A getPlan() 0 4 1
A getTime() 0 4 1
A setId() 10 10 3

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
 * PHP Billing Library
4
 *
5
 * @link      https://github.com/hiqdev/php-billing
6
 * @package   php-billing
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\sale;
12
13
use DateTime;
14
use hiqdev\php\billing\customer\CustomerInterface;
15
use hiqdev\php\billing\plan\PlanInterface;
16
use hiqdev\php\billing\target\TargetInterface;
17
18
/**
19
 * Sale.
20
 *
21
 * @author Andrii Vasyliev <[email protected]>
22
 */
23
class Sale implements SaleInterface
24
{
25
    /**
26
     * @var int
27
     */
28
    protected $id;
29
30
    /**
31
     * @var TargetInterface
32
     */
33
    protected $target;
34
35
    /**
36
     * @var CustomerInterface
37
     */
38
    protected $customer;
39
40
    /**
41
     * @var PlanInterface
42
     */
43
    protected $plan;
44
45
    /**
46
     * @var DateTime
47
     */
48
    protected $time;
49
50 View Code Duplication
    public function __construct(
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...
51
                            $id,
52
        TargetInterface     $target,
53
        CustomerInterface   $customer,
54
        PlanInterface       $plan,
55
        DateTime            $time = null
56
    ) {
57
        $this->id = $id;
58
        $this->target = $target;
59
        $this->customer = $customer;
60
        $this->plan = $plan;
61
        $this->time = $time;
62
    }
63
64
    public function getId()
65
    {
66
        return $this->id;
67
    }
68
69
    public function getTarget()
70
    {
71
        return $this->target;
72
    }
73
74
    public function getCustomer()
75
    {
76
        return $this->customer;
77
    }
78
79
    public function getPlan()
80
    {
81
        return $this->plan;
82
    }
83
84
    public function getTime()
85
    {
86
        return $this->time;
87
    }
88
89 View Code Duplication
    public function setId($id)
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...
90
    {
91
        if ($this->id === $id) {
92
            return;
93
        }
94
        if ($this->id !== null) {
95
            throw new \Exception('cannot reassign sale id');
96
        }
97
        $this->id = $id;
98
    }
99
}
100