Completed
Pull Request — master (#73)
by Paweł
06:57
created

BillingAddressTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 92
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 1
dl 92
loc 92
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getBillingAddress() 4 4 1
A setBillingAddress() 6 6 1
A updateBillingAddress() 14 14 2

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 Xsolve\SalesforceClient\Model;
4
5
use JMS\Serializer\Annotation as JMS;
6
use Xsolve\SalesforceClient\Model\ValueObject\Address;
7
8 View Code Duplication
trait BillingAddressTrait
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
    /**
11
     * @var string|null
12
     * @JMS\Type("string")
13
     * @JMS\Groups({"update", "create"})
14
     */
15
    protected $billingStreet;
16
17
    /**
18
     * @var string|null
19
     * @JMS\Type("string")
20
     * @JMS\Groups({"update", "create"})
21
     */
22
    protected $billingCity;
23
24
    /**
25
     * @var string|null
26
     * @JMS\Type("string")
27
     * @JMS\Groups({"update", "create"})
28
     */
29
    protected $billingState;
30
31
    /**
32
     * @var string|null
33
     * @JMS\Type("string")
34
     * @JMS\Groups({"update", "create"})
35
     */
36
    protected $billingPostalCode;
37
38
    /**
39
     * @var string|null
40
     * @JMS\Type("string")
41
     * @JMS\Groups({"update", "create"})
42
     */
43
    protected $billingCountry;
44
45
    /**
46
     * @var float|null
47
     * @JMS\Type("float")
48
     * @JMS\Groups({"update", "create"})
49
     */
50
    protected $billingLatitude;
51
52
    /**
53
     * @var float|null
54
     * @JMS\Type("float")
55
     * @JMS\Groups({"update", "create"})
56
     */
57
    protected $billingLongitude;
58
59
    /**
60
     * @var Address|null
61
     * @JMS\Type("Xsolve\SalesforceClient\Model\ValueObject\Address")
62
     */
63
    protected $billingAddress;
64
65
    /**
66
     * @return Address|null
67
     */
68
    public function getBillingAddress()
69
    {
70
        return $this->billingAddress;
71
    }
72
73
    public function setBillingAddress(Address $billingAddress): self
74
    {
75
        $this->billingAddress = $billingAddress;
76
77
        return $this;
78
    }
79
80
    /**
81
     * Because BillingAddress is not writtable.
82
     *
83
     * @JMS\PreSerialize
84
     */
85
    public function updateBillingAddress()
86
    {
87
        if (!$this->billingAddress instanceof Address) {
88
            return;
89
        }
90
91
        $this->billingCity = $this->billingAddress->getCity();
92
        $this->billingCountry = $this->billingAddress->getCountry();
93
        $this->billingLatitude = $this->billingAddress->getLatitude();
94
        $this->billingLongitude = $this->billingAddress->getLongitude();
95
        $this->billingPostalCode = $this->billingAddress->getPostalCode();
96
        $this->billingState = $this->billingAddress->getState();
97
        $this->billingStreet = $this->billingAddress->getStreet();
98
    }
99
}
100