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

LastCombination   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0
ccs 0
cts 16
cp 0
rs 10

3 Methods

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