Completed
Push — master ( 888950...2eb122 )
by Andrii
05:25
created

FormulaChargeModifierTrait::setFormula()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\charge;
12
13
use hiqdev\php\billing\action\ActionInterface;
14
15
/**
16
 * Price with formula
17
 * Provides charge modification (recalculation) with formula.
18
 *
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21
trait FormulaChargeModifierTrait
22
{
23
    /**
24
     * @var ChargeModifier|null
25
     */
26
    protected $formula;
27
28
    /**
29
     * Calculate additional charges.
30
     *
31
     * @param ActionInterface $action
32
     * @param ChargeInterface $charge
33
     * @return ChargeInterface[] calculated charges
34
     */
35
    public function modifyCharge(ChargeInterface $charge, ActionInterface $action): array
36
    {
37
        return $formula ? $formula->modifyCharge($charge, $action) : [];
0 ignored issues
show
Bug introduced by
The variable $formula does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
38
    }
39
40
    public function setFormula(ChargeModifier $formula)
41
    {
42
        $this->formula = $formula;
43
    }
44
}
45