Completed
Push — master ( eebd57...9e79a2 )
by Andrii
07:00
created

FormulaChargeModifierTrait::isSuitable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 2
cp 0
rs 10
cc 2
eloc 2
nc 2
nop 2
crap 6
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
    /** {@inheritdoc} */
29
    public function modifyCharge(?ChargeInterface $charge, ActionInterface $action): array
30
    {
31
        return $this->formula ? $this->formula->modifyCharge($charge, $action) : [];
32
    }
33
34
    /** {@inheritdoc} */
35
    public function isSuitable(?ChargeInterface $charge, ActionInterface $action): bool
36
    {
37
        return $this->formula ? $this->formula->isSuitable($charge, $action) : false;
38
    }
39
40
    public function setFormula(ChargeModifier $formula)
41
    {
42
        $this->formula = $formula;
43
    }
44
}
45