Completed
Pull Request — master (#147)
by Serhii
14:54
created

OrderManager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 5
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addOrderToTicket() 0 5 1
A removeOrderFromTicket() 0 4 1
A getCustomerOrder() 0 18 2
1
<?php
2
3
namespace AppBundle\Services;
4
5
use AppBundle\Entity\CustomerOrder;
6
use AppBundle\Entity\Ticket;
7
use AppBundle\Repository\CustomerOrderRepository;
8
use Symfony\Bridge\Doctrine\RegistryInterface;
9
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
10
11
class OrderManager
12
{
13
    protected $doctrine;
14
15
    protected $tokenStorage;
16
17
    public function __construct(RegistryInterface $doctrine, TokenStorageInterface $tokenStorage)
18
    {
19
        $this->doctrine = $doctrine;
20
        $this->tokenStorage = $tokenStorage;
21
    }
22
23
    public function addOrderToTicket(Ticket $ticket)
24
    {
25
        $order = $this->getCustomerOrder();
26
        $ticket->setCustomerOrder($order);
27
    }
28
29
    public function removeOrderFromTicket(Ticket $ticket)
30
    {
31
        $ticket->setCustomerOrder(null);
32
    }
33
34
    private function getCustomerOrder()
35
    {
36
        $em = $this->doctrine->getEntityManager();
37
        /** @var CustomerOrderRepository $repository */
38
        $customerOrderRepository = $em->getRepository('AppBundle:CustomerOrder');
39
        //$customer = $this->tokenStorage->getToken()->getUser();
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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
        $customer = $em->getRepository('AppBundle:Customer')->findOneBy([]);
41
        $order = $customerOrderRepository->findLastOpenOrder($customer);
42
43
        /**
44
         * Creating order if isn't exist
45
         */
46
        if (!$order) {
47
            $order = new CustomerOrder($customer);
48
            $em->persist($order);
49
        }
50
        return $order;
51
    }
52
}
53