Completed
Push — master ( acc5b1...ec9928 )
by Paweł
45:45 queued 33:29
created

AddressComparator::normalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
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\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 self::normalize($firstAddress->getCity()) === self::normalize($secondAddress->getCity())
27
            && self::normalize($firstAddress->getStreet()) === self::normalize($secondAddress->getStreet())
28
            && self::normalize($firstAddress->getCompany()) === self::normalize($secondAddress->getCompany())
29
            && self::normalize($firstAddress->getPostcode()) === self::normalize($secondAddress->getPostcode())
30
            && self::normalize($firstAddress->getLastName()) === self::normalize($secondAddress->getLastName())
31
            && self::normalize($firstAddress->getFirstName()) === self::normalize($secondAddress->getFirstName())
32
            && self::normalize($firstAddress->getPhoneNumber()) === self::normalize($secondAddress->getPhoneNumber())
33
            && self::normalize($firstAddress->getCountryCode()) === self::normalize($secondAddress->getCountryCode())
34
            && self::normalize($firstAddress->getProvinceCode()) === self::normalize($secondAddress->getProvinceCode())
35
            && self::normalize($firstAddress->getProvinceName()) === self::normalize($secondAddress->getProvinceName())
36
        ;
37
    }
38
39
    /**
40
     * @param string $value
41
     *
42
     * @return string
43
     */
44
    private function normalize($value)
45
    {
46
        return trim(strtolower($value));
47
    }
48
}
49