Passed
Push — master ( 88fe71...f59922 )
by Hannes
02:55 queued 11s
created

DonorFactory::createDonor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 16
dl 0
loc 35
rs 9.7
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
 * This file is part of byrokrat\giroapp.
4
 *
5
 * byrokrat\giroapp is free software: you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License as published
7
 * by the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * byrokrat\giroapp is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with byrokrat\giroapp. If not, see <http://www.gnu.org/licenses/>.
17
 *
18
 * Copyright 2016-19 Hannes Forsgård
19
 */
20
21
declare(strict_types = 1);
22
23
namespace byrokrat\giroapp\Model;
24
25
use byrokrat\giroapp\State\StateCollection;
26
use byrokrat\banking\AccountFactoryInterface;
27
use byrokrat\id\IdFactoryInterface;
28
use byrokrat\amount\Currency\SEK;
29
30
class DonorFactory
31
{
32
    /** @var StateCollection */
33
    private $stateCollection;
34
35
    /** @var AccountFactoryInterface */
36
    private $accountFactory;
37
38
    /** @var IdFactoryInterface */
39
    private $idFactory;
40
41
    public function __construct(
42
        StateCollection $stateCollection,
43
        AccountFactoryInterface $accountFactory,
44
        IdFactoryInterface $idFactory
45
    ) {
46
        $this->stateCollection = $stateCollection;
47
        $this->accountFactory = $accountFactory;
48
        $this->idFactory = $idFactory;
49
    }
50
51
    /**
52
     * @param string[] $address
53
     * @param string[] $attributes
54
     */
55
    public function createDonor(
56
        string $mandateKey = '',
57
        string $state = '',
58
        string $stateDesc = '',
59
        string $mandateSource = '',
60
        string $payerNumber = '',
61
        string $accountNumber = '',
62
        string $donorId = '',
63
        string $name = '',
64
        array $address = [],
65
        string $email = '',
66
        string $phone = '',
67
        string $donationAmount = '0',
68
        string $comment = '',
69
        string $created = '',
70
        string $updated = '',
71
        array $attributes = []
72
    ): Donor {
73
        return new Donor(
74
            $mandateKey,
75
            $this->stateCollection->getState($state),
76
            $stateDesc,
77
            $mandateSource,
78
            $payerNumber,
79
            $this->accountFactory->createAccount($accountNumber),
80
            $this->idFactory->createId($donorId),
81
            $name,
82
            new PostalAddress(...$address),
0 ignored issues
show
Bug introduced by
$address is expanded, but the parameter $line1 of byrokrat\giroapp\Model\P...lAddress::__construct() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

82
            new PostalAddress(/** @scrutinizer ignore-type */ ...$address),
Loading history...
83
            $email,
84
            $phone,
85
            new SEK($donationAmount),
86
            $comment,
87
            new \DateTimeImmutable($created),
88
            new \DateTimeImmutable($updated),
89
            $attributes
90
        );
91
    }
92
}
93