Completed
Push — simplify-address-comparator ( 262042 )
by Kamil
34:02 queued 07:22
created

AddressComparator::same()   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 2
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\Addressing\Comparator;
13
14
use Sylius\Component\Addressing\Model\AddressInterface;
15
16
/**
17
 * @author Jan Góralski <[email protected]>
18
 */
19
final class AddressComparator implements AddressComparatorInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function same(AddressInterface $firstAddress, AddressInterface $secondAddress)
25
    {
26
        return $this->normalizeAddress($firstAddress) === $this->normalizeAddress($secondAddress);
27
    }
28
29
    /**
30
     * @param AddressInterface $address
31
     *
32
     * @return array
33
     */
34
    private function normalizeAddress(AddressInterface $address)
35
    {
36
        return array_map(function ($value) {
37
            return trim(strtolower($value));
38
        }, [
39
            $address->getCity(),
40
            $address->getCompany(),
41
            $address->getCountryCode(),
42
            $address->getFirstName(),
43
            $address->getLastName(),
44
            $address->getPhoneNumber(),
45
            $address->getPostcode(),
46
            $address->getProvinceCode(),
47
            $address->getProvinceName(),
48
            $address->getStreet(),
49
        ]);
50
    }
51
}
52