for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace OroCRM\Bundle\MagentoBundle\Manager\CustomerAddress;
use Symfony\Component\PropertyAccess\PropertyAccess;
use OroCRM\Bundle\ContactBundle\Entity\ContactAddress;
use OroCRM\Bundle\MagentoBundle\Entity\Address;
class ConvertAddressToContactAdress
{
protected $baseAddressProperties = [
'label',
'street',
'street2',
'city',
'postalCode',
'country',
'organization',
'region',
'regionText',
'namePrefix',
'firstName',
'middleName',
'lastName',
'nameSuffix',
'types',
'primary'
];
public function __construct()
$this->accessor = PropertyAccess::createPropertyAccessor();
accessor
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;
}
/**
* @param Address $customerAddress
*
* @return ContactAddress
*/
public function convert(Address $customerAddress)
$contactAddress = new ContactAddress();
foreach ($this->baseAddressProperties as $property) {
$this->accessor->setValue(
$contactAddress,
$property,
$this->accessor->getValue($customerAddress, $property)
);
return $contactAddress;
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: