Completed
Push — master ( 8f4045...77b660 )
by Andrii
04:19
created

Plan   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 17.91 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 12
loc 67
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPrices() 0 4 1
A calculateCharges() 12 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing;
12
13
/**
14
 * Tariff Plan.
15
 *
16
 * @author Andrii Vasyliev <[email protected]>
17
 */
18
class Plan
19
{
20
    /**
21
     * @var int
22
     */
23
    protected $id;
24
25
    /**
26
     * @var string
27
     */
28
    protected $name;
29
30
    /**
31
     * @var Plan|null
32
     * XXX not sure to implement
33
     */
34
    protected $parent;
35
36
    /**
37
     * @var Client
38
     */
39
    protected $client;
40
41
    /**
42
     * @var Target
43
     */
44
    protected $target;
45
46
    /**
47
     * @var PriceInterface[]
48
     */
49
    protected $prices = [];
50
51
    /**
52
     * @param PriceInterface[] $prices
53
     */
54
    public function __construct(array $prices)
55
    {
56
        $this->prices = $prices;
57
    }
58
59
    /**
60
     * @return PriceInterface[]
61
     */
62
    public function getPrices()
63
    {
64
        return $this->prices;
65
    }
66
67
    /**
68
     * Calculate charges for given action.
69
     * @param ActionInterface $action
70
     * @return Charge[]
71
     */
72 View Code Duplication
    public function calculateCharges(ActionInterface $action)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74
        $charges = [];
75
        foreach ($this->prices as $price) {
76
            $charge = $price->calculateCharge($action);
0 ignored issues
show
Bug introduced by
The method calculateCharge() does not seem to exist on object<hiqdev\php\billing\PriceInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
77
            if ($charge !== null) {
78
                $charges[] = $charge;
79
            }
80
        }
81
82
        return $charges;
83
    }
84
}
85