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

FormulaChargeModifierTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 24
rs 10
c 0
b 0
f 0
ccs 0
cts 5
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A modifyCharge() 0 4 2
A setFormula() 0 4 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-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