|
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 |
|
|
|
|
|
|
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
|
|
|
} |
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.