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

AbstractDumper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 20.69 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 6
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A formatName() 6 21 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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