Completed
Push — 1.10 ( 93e51c...7f32fb )
by
unknown
11:06
created

ConvertAddressToContactAdress   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 45
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A convert() 0 13 2
1
<?php
2
3
namespace OroCRM\Bundle\MagentoBundle\Manager\CustomerAddress;
4
5
use Symfony\Component\PropertyAccess\PropertyAccess;
6
7
use OroCRM\Bundle\ContactBundle\Entity\ContactAddress;
8
use OroCRM\Bundle\MagentoBundle\Entity\Address;
9
10
class ConvertAddressToContactAdress
11
{
12
    protected $baseAddressProperties = [
13
        'label',
14
        'street',
15
        'street2',
16
        'city',
17
        'postalCode',
18
        'country',
19
        'organization',
20
        'region',
21
        'regionText',
22
        'namePrefix',
23
        'firstName',
24
        'middleName',
25
        'lastName',
26
        'nameSuffix',
27
        'types',
28
        'primary'
29
    ];
30
31
    public function __construct()
32
    {
33
        $this->accessor = PropertyAccess::createPropertyAccessor();
0 ignored issues
show
Bug introduced by
The property accessor does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
34
    }
35
36
    /**
37
     * @param Address $customerAddress
38
     *
39
     * @return ContactAddress
40
     */
41
    public function convert(Address $customerAddress)
42
    {
43
        $contactAddress = new ContactAddress();
44
        foreach ($this->baseAddressProperties as $property) {
45
            $this->accessor->setValue(
46
                $contactAddress,
47
                $property,
48
                $this->accessor->getValue($customerAddress, $property)
49
            );
50
        }
51
52
        return $contactAddress;
53
    }
54
}
55