Completed
Push — master ( 636a3e...0d9cfe )
by Joachim
12:23
created

OrderLineManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
namespace Loevgaard\DandomainAltapayBundle\Manager;
3
4
use Doctrine\Common\Persistence\ObjectManager;
5
use Doctrine\Common\Persistence\ObjectRepository;
6
use Loevgaard\DandomainAltapayBundle\Entity\OrderLineInterface;
7
use Loevgaard\DandomainAltapayBundle\Entity\TerminalInterface;
8
9
class OrderLineManager
10
{
11
    /**
12
     * @var ObjectManager
13
     */
14
    protected $objectManager;
15
16
    /**
17
     * @var string
18
     */
19
    protected $class;
20
21
    public function __construct(ObjectManager $objectManager, string $class)
22
    {
23
        $this->objectManager = $objectManager;
24
        $this->class = $class;
25
    }
26
27
    /**
28
     * @return ObjectRepository
29
     */
30
    protected function getRepository() : ObjectRepository
31
    {
32
        return $this->objectManager->getRepository($this->getClass());
33
    }
34
35
    /**
36
     * @return string
37
     */
38 View Code Duplication
    public function getClass() : string
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...
39
    {
40
        if (false !== strpos($this->class, ':')) {
41
            $metadata = $this->objectManager->getClassMetadata($this->class);
42
            $this->class = $metadata->getName();
43
        }
44
        return $this->class;
45
    }
46
47
    /**
48
     * @return OrderLineInterface
49
     */
50
    public function createOrderLine() : OrderLineInterface
51
    {
52
        $class = $this->getClass();
53
        $terminal = new $class();
54
        return $terminal;
55
    }
56
57
    /**
58
     * @param OrderLineInterface $orderLine
59
     */
60
    public function deleteOrderLine(OrderLineInterface $orderLine)
61
    {
62
        $this->objectManager->remove($orderLine);
63
        $this->objectManager->flush();
64
    }
65
66
    /**
67
     * @param OrderLineInterface $orderLine
68
     * @param bool $flush
69
     */
70
    public function updateOrderLine(OrderLineInterface $orderLine, bool $flush = true)
71
    {
72
        $this->objectManager->persist($orderLine);
73
74
        if($flush) {
75
            $this->objectManager->flush();
76
        }
77
    }
78
}