Completed
Push — master ( 7c1eaa...80d841 )
by Joachim
15:53
created

PaymentLineManager   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 65
Duplicated Lines 32.31 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 1
dl 21
loc 65
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B createPaymentLineFromDandomainPaymentRequest() 21 30 6
A create() 0 4 1
A delete() 0 4 1
A update() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
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