Code Duplication    Length = 13-17 lines in 2 locations

src/_ideas/Billing.php 1 location

@@ 34-50 (lines=17) @@
31
        return $this->aggregateCharges($charges);
32
    }
33
34
    public function calculateCharges(OrderInterface $order)
35
    {
36
        $planRepo = $this->entityManager->getRepository(Plan::class);
37
        // TODO should be like this:
38
        // $spec = Specification::fromArray(['order' => $order]);
39
        // $plans = $planRepo->findAll($spec);
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
    {

src/order/Calculator.php 1 location

@@ 27-39 (lines=13) @@
24
        $this->repository = $repository;
25
    }
26
27
    public function calculateCharges(OrderInterface $order)
28
    {
29
        $plans = $this->repository->findByOrder($order);
30
        $charges = [];
31
        foreach ($order->getActions() as $actionKey => $action) {
32
            if (empty($plans[$actionKey])) {
33
                throw new FailedFindPlan();
34
            }
35
            $charges[$actionKey] = $plans[$actionKey]->calculateCharges($action);
36
        }
37
38
        return $charges;
39
    }
40
}
41