Completed
Push — master ( 9a6247...f45029 )
by Andrii
03:27
created

SettableChargeModifierTrait::modifyCharge()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.1406

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 3
nop 2
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 3.1406
rs 10
c 0
b 0
f 0
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
 * Adds modifier property and implements ChargeModifier interface.
17
 *
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
trait SettableChargeModifierTrait
21
{
22
    /**
23
     * @var ChargeModifier|null
24
     */
25
    protected $modifier;
26
27
    /** {@inheritdoc} */
28 4
    public function modifyCharge(?ChargeInterface $charge, ActionInterface $action): array
29
    {
30 4
        if ($this->modifier !== null) {
31
            return $this->modifier->modifyCharge($charge, $action);
32
        }
33
34 4
        return $charge ? [$charge] : [];
35
    }
36
37
    /** {@inheritdoc} */
38
    public function isSuitable(?ChargeInterface $charge, ActionInterface $action): bool
39
    {
40
        return $this->modifier ? $this->modifier->isSuitable($charge, $action) : false;
41
    }
42
43
    public function setModifier(ChargeModifier $modifier)
44
    {
45
        $this->modifier = $modifier;
46
    }
47
}
48