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

TemporaryAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 35
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A createAsSubaction() 0 12 1
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