Completed
Push — master ( c66308...141223 )
by Kamil
28:38 queued 09:41
created

CustomerUniqueAddressAdder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Component\Core\Customer;
13
14
use Sylius\Component\Addressing\Comparator\AddressComparatorInterface;
15
use Sylius\Component\Core\Model\AddressInterface;
16
use Sylius\Component\Core\Model\CustomerInterface;
17
18
/**
19
 * @author Jan Góralski <[email protected]>
20
 */
21
final class CustomerUniqueAddressAdder implements CustomerAddressAdderInterface
22
{
23
    /**
24
     * @var AddressComparatorInterface
25
     */
26
    private $addressComparator;
27
28
    /**
29
     * @param AddressComparatorInterface $addressComparator
30
     */
31
    public function __construct(AddressComparatorInterface $addressComparator)
32
    {
33
        $this->addressComparator = $addressComparator;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function add(CustomerInterface $customer, AddressInterface $address)
40
    {
41
        foreach ($customer->getAddresses() as $customerAddress) {
42
            if ($this->addressComparator->equal($customerAddress, $address)) {
43
                return;
44
            }
45
        }
46
47
        $customer->addAddress($address);
48
    }
49
}
50