Test Failed
Pull Request — master (#11)
by
unknown
01:58
created

Details   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 22.92 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 11
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A placeId() 0 6 1
A osmId() 11 11 2

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 PHP Nominatim.
7
 * (c) Maxime Hélias <[email protected]>
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace maxh\Nominatim;
13
14
use maxh\Nominatim\Exceptions\InvalidParameterException;
15
16
/**
17
 * Lookup details about a single place by id.
18
 *
19
 * @see http://wiki.openstreetmap.org/wiki/Nominatim
20
 */
21
class Details extends Query
22
{
23
    /**
24
     * Constructor.
25
     *
26
     * @param array $query Default value for this query
27
     */
28
    public function __construct(array &$query = [])
29
    {
30
        parent::__construct($query);
31
32
        $this->setPath('details');
33
34
        $this->acceptedFormat[] = 'html';
35
        $this->acceptedFormat[] = 'jsonv2';
36
    }
37
38
    /**
39
     * Place information by placeId.
40
     *
41
     * @return Details
42
     */
43
    public function placeId(int $placeId): self
44
    {
45
        $this->query['place_id'] = $placeId;
46
47
        return $this;
48
    }
49
50
    /**
51
     * Place information by osmtype and osmid.
52
     *
53
     * @throws InvalidParameterException
54
     *
55
     * @return Details
56
     */
57 View Code Duplication
    public function osmId(string $osmType, int $osmId): self
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
58
    {
59
        if (!\in_array($osmType, Consts\OsmTypes::all(), true)) {
60
            throw new InvalidParameterException('Osm type is invalid');
61
        }
62
63
        $this->query['osmtype'] = $osmType;
64
        $this->query['osmid'] = $osmId;
65
66
        return $this;
67
    }
68
}
69