Completed
Push — master ( f98298...3d080b )
by Andrii
02:02
created

Billing::aggregateCharges()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
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\order;
12
13
use hiqdev\php\billing\order\OrderInterface;
14
15
/**
16
 * @author Andrii Vasyliev <[email protected]>
17
 */
18
class Billing
19
{
20
    public $entityManager;
21
22
    public function __construct(EntityManagerInterface $entityManager)
23
    {
24
        $this->entityManager = $entityManager;
25
    }
26
27
    public function calculateBills(OrderInterface $order)
28
    {
29
        $charges = $this->calculateCharges($order);
30
31
        return $this->aggregateCharges($charges);
32
    }
33
34 View Code Duplication
    public function calculateCharges(OrderInterface $order)
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...
35
    {
36
        $planRepo = $this->entityManager->getRepository(Plan::class);
37
        // TODO should be like this:
38
        // $spec = Specification::fromArray(['order' => $order]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
39
        // $plans = $planRepo->findAll($spec);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
40
        $plans = $planRepo->findByOrder($order);
41
        $charges = [];
42
        foreach ($order->getActions() as $actionKey => $action) {
43
            if (empty($plans[$actionKey])) {
44
                throw new FailedFindPlan();
45
            }
46
            $charges[$actionKey] = $plans[$actionKey]->calculateCharges($action);
47
        }
48
49
        return $charges;
50
    }
51
52
    public function aggregateCharges(array $charges)
53
    {
54
        var_dump(__METHOD__);
0 ignored issues
show
Security Debugging Code introduced by
var_dump(__METHOD__); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
55
        var_dump($charges);
56
57
        die(__METHOD__);
0 ignored issues
show
Coding Style Compatibility introduced by
The method aggregateCharges() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
58
    }
59
}
60