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

LastCombination::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 4
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\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
    public function __construct(ChargeModifier $left, ChargeModifier $right)
25
    {
26
        $this->left = $left;
0 ignored issues
show
Bug introduced by
The property left does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
        $this->right = $right;
0 ignored issues
show
Bug introduced by
The property right does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
    }
29
30
    public function modifyCharge(?ChargeInterface $charge, ActionInterface $action): array
31
    {
32
        if ($this->right->isSuitable($charge, $action)) {
33
            return $this->right->modifyCharge($charge, $action);
34
        }
35
36
        return $this->left->modifyCharge($charge, $action);
37
    }
38
39
    public function isSuitable(?ChargeInterface $charge, ActionInterface $action): bool
40
    {
41
        return $this->left->isSuitable($charge, $action) || $this->right->isSuitable($charge, $action);
42
    }
43
}
44