Transaction::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 9
dl 0
loc 20
rs 9.9666
c 0
b 0
f 0

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
declare(strict_types=1);
4
5
namespace Beccha\OfxParser\Entity;
6
7
use DateTime;
8
9
final class Transaction
10
{
11
    /**
12
     * @var array|string[]
13
     */
14
    private array $types = array(
15
        "CREDIT"      => "Generic credit",
16
        "DEBIT"       => "Generic debit",
17
        "INT"         => "Interest earned or paid ",
18
        "DIV"         => "Dividend",
19
        "FEE"         => "FI fee",
20
        "SRVCHG"      => "Service charge",
21
        "DEP"         => "Deposit",
22
        "ATM"         => "ATM debit or credit",
23
        "POS"         => "Point of sale debit or credit ",
24
        "XFER"        => "Transfer",
25
        "CHECK"       => "Cheque",
26
        "PAYMENT"     => "Electronic payment",
27
        "CASH"        => "Cash withdrawal",
28
        "DIRECTDEP"   => "Direct deposit",
29
        "DIRECTDEBIT" => "Merchant initiated debit",
30
        "REPEATPMT"   => "Repeating payment/standing order",
31
        "OTHER"       => "Other"
32
    );
33
    private string $type;
34
    private DateTime $date;
35
    private int $amount;
36
    private string $uniqueId;
37
    private string $name;
38
    private string $memo;
39
    private string $sic;
40
    private string $checkNumber;
41
    private Payee $payee;
42
43
    public function __construct(
44
        string $type,
45
        DateTime $date,
46
        float $amount,
47
        string $uniqueId,
48
        string $name,
49
        string $memo,
50
        string $sic,
51
        string $checkNumber,
52
        Payee $payee
53
    ) {
54
        $this->type = $type;
55
        $this->date = $date;
56
        $this->amount = (int)(\bcmul((string)$amount, '100'));
57
        $this->uniqueId = $uniqueId;
58
        $this->name = $name;
59
        $this->memo = $memo;
60
        $this->sic = $sic;
61
        $this->checkNumber = $checkNumber;
62
        $this->payee = $payee;
63
    }
64
65
    public function getPayee(): Payee
66
    {
67
        return $this->payee;
68
    }
69
70
    public function getType(): string
71
    {
72
        return $this->type;
73
    }
74
75
    public function getDate(): DateTime
76
    {
77
        return $this->date;
78
    }
79
80
    public function getAmount(): int
81
    {
82
        return $this->amount;
83
    }
84
85
    public function getUniqueId(): string
86
    {
87
        return $this->uniqueId;
88
    }
89
90
    public function getName(): string
91
    {
92
        return $this->name;
93
    }
94
95
    public function getMemo(): string
96
    {
97
        return $this->memo;
98
    }
99
100
    public function getSic(): string
101
    {
102
        return $this->sic;
103
    }
104
105
    public function getCheckNumber(): string
106
    {
107
        return $this->checkNumber;
108
    }
109
110
    public function getTypeDescription(): string
111
    {
112
        return $this->types[$this->type] ?? '';
113
    }
114
}
115