LastCombination::modifyCharge()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 3
c 1
b 0
f 1
nc 2
nop 2
dl 0
loc 7
ccs 0
cts 6
cp 0
crap 6
rs 10
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-2020, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\charge\modifiers;
12
13
use hiqdev\php\billing\action\ActionInterface;
14
use hiqdev\php\billing\charge\ChargeInterface;
15
use hiqdev\php\billing\charge\ChargeModifier;
16
17
/**
18
 * Last combination.
19
 *
20
 * @author Andrii Vasyliev <[email protected]>
21
 */
22
class LastCombination implements ChargeModifier
23
{
24
    /**
25
     * @var ChargeModifier
26
     */
27
    protected $left;
28
    /**
29
     * @var ChargeModifier
30
     */
31
    protected $right;
32
33
    public function __construct(ChargeModifier $left, ChargeModifier $right)
34
    {
35
        $this->left = $left;
36
        $this->right = $right;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function modifyCharge(?ChargeInterface $charge, ActionInterface $action): array
43
    {
44
        if ($this->right->isSuitable($charge, $action)) {
45
            return $this->right->modifyCharge($charge, $action);
46
        }
47
48
        return $this->left->modifyCharge($charge, $action);
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function isSuitable(?ChargeInterface $charge, ActionInterface $action): bool
55
    {
56
        return $this->left->isSuitable($charge, $action) || $this->right->isSuitable($charge, $action);
57
    }
58
}
59