BankAccount::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
c 0
b 0
f 0
nc 1
nop 8
dl 0
loc 18
rs 10

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 BankAccount
10
{
11
    private string $agencyNumber;
12
    private string $accountNumber;
13
    private string $accountType;
14
    private int $balance;
15
    private DateTime $balanceDate;
16
    private string $routingNumber;
17
    private Statement $statement;
18
    private string $transactionUid;
19
20
    public function __construct(
21
        string $agencyNumber,
22
        string $accountNumber,
23
        string $accountType,
24
        float $balance,
25
        DateTime $balanceDate,
26
        string $routingNumber,
27
        Statement $statement,
28
        string $transactionUid
29
    ) {
30
        $this->agencyNumber = $agencyNumber;
31
        $this->accountNumber = $accountNumber;
32
        $this->accountType = $accountType;
33
        $this->balance = (int)\bcmul((string)$balance, '100');
34
        $this->balanceDate = $balanceDate;
35
        $this->routingNumber = $routingNumber;
36
        $this->statement = $statement;
37
        $this->transactionUid = $transactionUid;
38
    }
39
40
    public function getAgencyNumber(): string
41
    {
42
        return $this->agencyNumber;
43
    }
44
45
    public function getAccountNumber(): string
46
    {
47
        return $this->accountNumber;
48
    }
49
50
    public function getAccountType(): string
51
    {
52
        return $this->accountType;
53
    }
54
55
    public function getBalance(): int
56
    {
57
        return $this->balance;
58
    }
59
60
    public function getBalanceDate(): DateTime
61
    {
62
        return $this->balanceDate;
63
    }
64
65
    public function getRoutingNumber(): string
66
    {
67
        return $this->routingNumber;
68
    }
69
70
    public function getStatement(): Statement
71
    {
72
        return $this->statement;
73
    }
74
75
    public function getTransactionUid(): string
76
    {
77
        return $this->transactionUid;
78
    }
79
}
80