Passed
Push — master ( efb60b...c5544e )
by Maxime
04:34 queued 02:32
created

Details   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 66
loc 66
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A placeId() 6 6 1
A osmType() 10 10 2
A osmId() 6 6 1

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 View Code Duplication
class Details extends Query
0 ignored issues
show
Duplication introduced by
This class 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...
22
{
23
    /**
24
     * OSM Type accepted (Node/Way/Relation).
25
     *
26
     * @var array
27
     */
28
    private $osmType = ['N', 'W', 'R'];
29
30
    /**
31
     * Constructor.
32
     *
33
     * @param array $query Default value for this query
34
     */
35
    public function __construct(array &$query = [])
36
    {
37
        parent::__construct($query);
38
39
        $this->setPath('details');
40
41
        $this->acceptedFormat[] = 'html';
42
        $this->acceptedFormat[] = 'jsonv2';
43
    }
44
45
    /**
46
     * Place information by placeId.
47
     *
48
     * @return Details
49
     */
50
    public function placeId(int $placeId): self
51
    {
52
        $this->query['place_id'] = $placeId;
53
54
        return $this;
55
    }
56
57
    /**
58
     * [osmType description].
59
     *
60
     * @throws \maxh\Nominatim\Exceptions\InvalidParameterException if osm type is not supported
61
     *
62
     * @return \maxh\Nominatim\Reverse
63
     */
64
    public function osmType(string $type): self
65
    {
66
        if (\in_array($type, $this->osmType, true)) {
67
            $this->query['osmtype'] = $type;
68
69
            return $this;
70
        }
71
72
        throw new InvalidParameterException('OSM Type is not supported');
73
    }
74
75
    /**
76
     * Place information by osmtype and osmid.
77
     *
78
     * @return Details
79
     */
80
    public function osmId(int $osmId): self
81
    {
82
        $this->query['osmid'] = $osmId;
83
84
        return $this;
85
    }
86
}
87