Completed
Push — master ( 41f74f...866870 )
by Andrii
03:39
created

Bill::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 19
ccs 0
cts 19
cp 0
rs 9.4285
cc 1
eloc 17
nc 1
nop 8
crap 2

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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;
12
13
use DateTime;
14
use hiqdev\php\billing\customer\Customer;
15
use hiqdev\php\billing\target\Target;
16
use hiqdev\php\units\Quantity;
17
use Money\Money;
18
19
/**
20
 * Bill.
21
 *
22
 * @author Andrii Vasyliev <[email protected]>
23
 */
24
class Bill implements EntityInterface
25
{
26
    /**
27
     * @var integer
28
     */
29
    protected $id;
30
31
    /**
32
     * @var Type
33
     */
34
    protected $type;
35
36
    /**
37
     * @var DateTime
38
     */
39
    protected $time;
40
41
    /**
42
     * @var Money
43
     */
44
    protected $sum;
45
46
    /**
47
     * @var Quantity
48
     */
49
    protected $quantity;
50
51
    /**
52
     * @var Customer
53
     */
54
    protected $customer;
55
56
    /**
57
     * @var Target
58
     */
59
    protected $target;
60
61
    /**
62
     * @var Plan
63
     */
64
    protected $plan;
65
66
    /**
67
     * @var bool
68
     */
69
    protected $isFinished;
70
71
    /**
72
     * @var Charge[]
73
     */
74
    protected $charges = [];
75
76
    public function __construct(
77
                    $id,
78
        Type        $type,
79
        DateTime    $time,
80
        Money       $sum,
81
        Quantity    $quantity,
82
        Customer    $customer = null,
83
        Target      $target = null,
84
        Plan        $plan = null
85
    ) {
86
        $this->id       = $id;
87
        $this->type     = $type;
88
        $this->time     = $time;
89
        $this->sum      = $sum;
90
        $this->quantity = $quantity;
91
        $this->customer = $customer;
92
        $this->target   = $target;
93
        $this->plan     = $plan;
94
    }
95
96
    public function jsonSerialize()
97
    {
98
        return get_object_vars($this);
99
    }
100
}
101