Completed
Push — master ( 073f2f...b2ba42 )
by Joachim
12:40
created

PaymentException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 11.29 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 7
loc 62
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 7 7 1
A getRequest() 0 4 1
A setRequest() 0 5 1
A getPayment() 0 4 1
A setPayment() 0 5 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
namespace Loevgaard\DandomainAltapayBundle\Exception;
3
4
use Loevgaard\DandomainAltapayBundle\Entity\PaymentInterface;
5
use Symfony\Component\HttpFoundation\Request;
6
7
class PaymentException extends Exception
8
{
9
    /**
10
     * @var Request
11
     */
12
    protected $request;
13
14
    /**
15
     * @var PaymentInterface
16
     */
17
    protected $payment;
18
19
    /**
20
     * @param string $message
21
     * @param Request $request
22
     * @param PaymentInterface $payment
23
     * @return PaymentException
24
     */
25 View Code Duplication
    public static function create(string $message, Request $request, PaymentInterface $payment) : PaymentException
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...
26
    {
27
        $e = new static($message);
28
        $e->setRequest($request);
29
        $e->setPayment($payment);
30
        return $e;
31
    }
32
33
    /**
34
     * @return Request
35
     */
36
    public function getRequest(): Request
37
    {
38
        return $this->request;
39
    }
40
41
    /**
42
     * @param Request $request
43
     * @return PaymentException
44
     */
45
    public function setRequest(Request $request) : PaymentException
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
46
    {
47
        $this->request = $request;
48
        return $this;
49
    }
50
51
    /**
52
     * @return PaymentInterface
53
     */
54
    public function getPayment() : PaymentInterface
55
    {
56
        return $this->payment;
57
    }
58
59
    /**
60
     * @param PaymentInterface $payment
61
     * @return PaymentException
62
     */
63
    public function setPayment(PaymentInterface $payment) : PaymentException
64
    {
65
        $this->payment = $payment;
66
        return $this;
67
    }
68
}