Completed
Push — master ( 14a2bb...4a945d )
by Andrii
02:47
created

Plan::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 4
crap 1
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\plan;
12
13
use hiqdev\php\billing\action\ActionInterface;
14
use hiqdev\php\billing\customer\CustomerInterface;
15
use hiqdev\php\billing\price\PriceInterface;
16
use hiqdev\php\billing\target\TargetInterface;
17
18
/**
19
 * Tariff Plan.
20
 *
21
 * @author Andrii Vasyliev <[email protected]>
22
 */
23
class Plan implements PlanInterface
24
{
25
    //  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...
26
    //  {
27
    //      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...
28
    //  }
29
30
    /**
31
     * @var int
32
     */
33
    protected $id;
34
35
    /**
36
     * @var string
37
     */
38
    protected $name;
39
40
    /**
41
     * @var Plan|null
42
     * XXX not sure to implement
43
     */
44
    protected $parent;
45
46
    /**
47
     * @var CustomerInterface
48
     */
49
    protected $seller;
50
51
    /**
52
     * @var PriceInterface[]
53
     */
54
    protected $prices = [];
55
56
    /**
57
     * @param PriceInterface[] $prices
58 1
     */
59
    public function __construct(
60
                            $id,
61
                            $name,
62
        CustomerInterface   $seller = null,
63
        array               $prices = []
64 1
    ) {
65 1
        $this->id = $id;
66 1
        $this->name = $name;
67 1
        $this->seller = $seller;
68 1
        $this->prices = $prices;
69
    }
70
71
    /**
72
     * @return PriceInterface[]
73
     */
74
    public function getPrices()
75
    {
76
        return $this->prices;
77
    }
78
79
    /**
80
     * Calculate charges for given action.
81
     * @param ActionInterface $action
82
     * @return Charge[]
83 1
     */
84
    public function calculateCharges(ActionInterface $action)
85 1
    {
86 1
        $charges = [];
87 1
        foreach ($this->prices as $price) {
88 1
            $charge = $action->calculateCharge($price);
89 1
            if ($charge !== null) {
90 1
                $charges[] = $charge;
91 1
            }
92
        }
93 1
94
        return $charges;
95
    }
96
97
    public function jsonSerialize()
98
    {
99
        return get_object_vars($this);
100
    }
101
}
102