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 |
|
|
|
|
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
|
|
|
|
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.