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

ConvertAddressToContactAdress::convert()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
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