Completed
Push — master ( 77b660...93750f )
by Andrii
02:18
created

Plan::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 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, 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 implements EntityInterface
19
{
20
    //  public static function instantiate($row)
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
21
    //  {
22
    //      return new static;
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
23
    //  }
24
25
    /**
26
     * @var int
27
     */
28
    protected $id;
29
30
    /**
31
     * @var string
32
     */
33
    protected $name;
34
35
    /**
36
     * @var Plan|null
37
     * XXX not sure to implement
38
     */
39
    protected $parent;
40
41
    /**
42
     * @var CustomerInterface
43
     */
44
    protected $seller;
45
46
    /**
47
     * @var Target
48
     */
49
    protected $target;
50
51
    /**
52
     * @var PriceInterface[]
53
     */
54
    protected $prices = [];
55
56
    /**
57
     * @param PriceInterface[] $prices
58
     */
59
    public function __construct($id, $name, CustomerInterface $seller, array $prices = [])
60
    {
61
        $this->id = $id;
62
        $this->name = $name;
63
        $this->seller = $seller;
64
        $this->prices = $prices;
65
    }
66
67
    /**
68
     * @return PriceInterface[]
69
     */
70
    public function getPrices()
71
    {
72
        return $this->prices;
73
    }
74
75
    /**
76
     * Calculate charges for given action.
77
     * @param ActionInterface $action
78
     * @return Charge[]
79
     */
80 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...
81
    {
82
        $charges = [];
83
        foreach ($this->prices as $price) {
84
            $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...
85
            if ($charge !== null) {
86
                $charges[] = $charge;
87
            }
88
        }
89
90
        return $charges;
91
    }
92
93
    public function jsonSerialize()
94
    {
95
        return get_object_vars($this);
96
    }
97
}
98