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