Completed
Push — master ( d99711...5ac685 )
by Dmitry
03:31
created

TemporaryAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 9
dl 0
loc 12
ccs 0
cts 11
cp 0
crap 2
rs 10
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
 * 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-2019, HiQDev (http://hiqdev.com/)
9
 */
10
namespace hiqdev\php\billing\action;
11
12
use DateTimeImmutable;
13
use hiqdev\php\billing\customer\CustomerInterface;
14
use hiqdev\php\billing\sale\SaleInterface;
15
use hiqdev\php\billing\target\TargetInterface;
16
use hiqdev\php\billing\type\TypeInterface;
17
use hiqdev\php\units\QuantityInterface;
18
19
/**
20
 * Class TemporaryAction represents an action, that is generated for
21
 * runtime-only purposes such as, but not limited to:
22
 *
23
 *  - Extending primary action with TemporaryActions, that represent client billing hierarchy
24
 *
25
 * Actions of this class MUST NOT be saved into the database and SHOULD be used
26
 * only for runtime calculations.
27
 *
28
 * @author Dmytro Naumenko <[email protected]>
29
 */
30
class TemporaryAction extends Action
31
{
32
    private function __construct(
33
        $id,
34
        TypeInterface $type,
35
        TargetInterface $target,
36
        QuantityInterface $quantity,
37
        CustomerInterface $customer,
38
        DateTimeImmutable $time,
39
        SaleInterface $sale = null,
40
        ActionState $state = null,
41
        ActionInterface $parent = null
42
    ) {
43
        parent::__construct($id, $type, $target, $quantity, $customer, $time, $sale, $state, $parent);
44
    }
45
46
    /**
47
     * Creates Temporary Action out of generic $action
48
     *
49
     * @param ActionInterface $action
50
     * @param CustomerInterface $customer
51
     * @return TemporaryAction
52
     */
53
    public static function createAsSubaction(ActionInterface $action, CustomerInterface $customer): TemporaryAction
54
    {
55
        return new self(
56
            null,
57
            $action->getType(),
58
            $action->getTarget(),
59
            $action->getQuantity(),
60
            $customer,
61
            $action->getTime(),
62
            null,
63
            $action->getState(),
64
            $action
65
        );
66
    }
67
}
68