Completed
Pull Request — master (#141)
by
unknown
34:11 queued 22:37
created

OrderManager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A removeOrderToTicket() 0 4 1
A addOrderToTicket() 0 5 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
    private $doctrine;
14
15
    private $tokenStorage;
16
17
    public function __construct(RegistryInterface $doctrine, TokenStorageInterface $tokenStorage)
18
    {
19
        $this->doctrine = $doctrine;
20
        $this->tokenStorage = $tokenStorage;
21
    }
22
23
    public function removeOrderToTicket(Ticket $ticket)
24
    {
25
        $ticket->setCustomerOrder(null);
26
    }
27
28
    public function addOrderToTicket(Ticket $ticket)
29
    {
30
        $order = $this->getCustomerOrder();
31
        $ticket->setCustomerOrder($order);
32
    }
33
34
    /**
35
     * @return CustomerOrder
36
     */
37
    public function getCustomerOrder(): CustomerOrder
38
    {
39
        $em = $this->doctrine->getEntityManager();
40
        /** @var CustomerOrderRepository $customerOrderRepository */
41
        $customerOrderRepository = $em->getRepository('AppBundle:CustomerOrder');
42
        //$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...
43
        $customer = $em->getRepository('AppBundle:Customer')->find(1);
44
        $order = $customerOrderRepository->findLastOpenOrder($customer);
45
        /**
46
         * Creating order if isn't exist
47
         */
48
        if (!$order) {
49
            $order = new CustomerOrder($customer);
50
            $em->persist($order);
51
        }
52
53
        return $order;
54
    }
55
}
56