1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainAltapayBundle\Manager; |
4
|
|
|
|
5
|
|
|
use Loevgaard\Dandomain\Pay\PaymentRequest\PaymentLine as DandomainPaymentLine; |
6
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\PaymentLine; |
7
|
|
|
use Loevgaard\DoctrineManager\Manager; |
8
|
|
|
|
9
|
|
|
class PaymentLineManager extends Manager |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* This will transform a PaymentRequest (parent) to a Payment (child). |
13
|
|
|
* |
14
|
|
|
* @param DandomainPaymentLine $dandomainPaymentLine |
15
|
|
|
* |
16
|
|
|
* @return PaymentLine |
17
|
|
|
*/ |
18
|
|
|
public function createPaymentLineFromDandomainPaymentRequest(DandomainPaymentLine $dandomainPaymentLine) |
19
|
|
|
{ |
20
|
|
|
$paymentLine = $this->create(); |
21
|
|
|
|
22
|
|
|
$methods = get_class_methods($dandomainPaymentLine); |
23
|
|
|
|
24
|
|
View Code Duplication |
foreach ($methods as $method) { |
|
|
|
|
25
|
|
|
if ('get' === substr($method, 0, 3)) { |
26
|
|
|
$val = $dandomainPaymentLine->{$method}(); |
27
|
|
|
$property = substr($method, 3); |
28
|
|
|
} elseif ('is' === substr($method, 0, 2)) { |
29
|
|
|
$val = $dandomainPaymentLine->{$method}(); |
30
|
|
|
$property = substr($method, 2); |
31
|
|
|
} else { |
32
|
|
|
continue; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if (!is_scalar($val)) { |
36
|
|
|
continue; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$setter = 'set'.$property; |
40
|
|
|
|
41
|
|
|
if (method_exists($paymentLine, $setter)) { |
42
|
|
|
$paymentLine->{$setter}($val); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return $paymentLine; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return PaymentLine |
51
|
|
|
*/ |
52
|
|
|
public function create() |
53
|
|
|
{ |
54
|
|
|
return parent::create(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param PaymentLine $obj |
59
|
|
|
*/ |
60
|
|
|
public function delete($obj) |
61
|
|
|
{ |
62
|
|
|
parent::delete($obj); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param PaymentLine $obj |
67
|
|
|
* @param bool $flush |
68
|
|
|
*/ |
69
|
|
|
public function update($obj, $flush = true) |
70
|
|
|
{ |
71
|
|
|
parent::update($obj, $flush); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
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.