Completed
Push — master ( 25e257...c0f64f )
by Dmitry
03:06
created

LastCombination   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 35
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A modifyCharge() 0 7 2
A __construct() 0 4 1
A isSuitable() 0 3 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\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