Completed
Push — master ( 9894be...cc7c8f )
by Tobias
21:38
created

AbstractDumper::formatName()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 21
Code Lines 11

Duplication

Lines 6
Ratio 28.57 %

Importance

Changes 0
Metric Value
dl 6
loc 21
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 11
nc 8
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Dumper;
14
15
use Geocoder\Location;
16
17
abstract class AbstractDumper
18
{
19
    /**
20
     * @param Location $address
21
     *
22
     * @return string
23
     */
24
    protected function formatName(Location $address): string
25
    {
26
        $name = [];
27
        $array = $address->toArray();
28
29
        foreach (['streetNumber', 'streetName', 'postalCode', 'locality'] as $attr) {
30
            $name[] = $array[$attr];
31
        }
32
33 View Code Duplication
        if (isset($array['adminLevels'][2])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
            $name[] = $array['adminLevels'][2]['name'];
35
        }
36
37 View Code Duplication
        if (isset($array['adminLevels'][1])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
            $name[] = $array['adminLevels'][1]['name'];
39
        }
40
41
        $name[] = $array['country'];
42
43
        return implode(', ', array_filter($name));
44
    }
45
}
46