geocoder-php /
Geocoder
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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\Query; |
||
| 14 | |||
| 15 | use Geocoder\Geocoder; |
||
| 16 | use Geocoder\Model\Coordinates; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @author Tobias Nyholm <[email protected]> |
||
| 20 | */ |
||
| 21 | final class ReverseQuery implements Query |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var Coordinates |
||
| 25 | */ |
||
| 26 | private $coordinates; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var string|null |
||
| 30 | */ |
||
| 31 | private $locale; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var int |
||
| 35 | */ |
||
| 36 | private $limit = Geocoder::DEFAULT_RESULT_LIMIT; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var array |
||
| 40 | */ |
||
| 41 | private $data = []; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param Coordinates $coordinates |
||
| 45 | */ |
||
| 46 | private function __construct(Coordinates $coordinates) |
||
| 47 | { |
||
| 48 | $this->coordinates = $coordinates; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param Coordinates $coordinates |
||
| 53 | * |
||
| 54 | * @return ReverseQuery |
||
| 55 | */ |
||
| 56 | public static function create(Coordinates $coordinates) |
||
| 57 | { |
||
| 58 | return new self($coordinates); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @param float $latitude |
||
| 63 | * @param float $longitude |
||
| 64 | * |
||
| 65 | * @return ReverseQuery |
||
|
0 ignored issues
–
show
|
|||
| 66 | */ |
||
| 67 | public static function fromCoordinates($latitude, $longitude): self |
||
| 68 | { |
||
| 69 | return new self(new Coordinates($latitude, $longitude)); |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param Coordinates $coordinates |
||
| 74 | * |
||
| 75 | * @return ReverseQuery |
||
| 76 | */ |
||
| 77 | public function withCoordinates(Coordinates $coordinates): self |
||
| 78 | { |
||
| 79 | $new = clone $this; |
||
| 80 | $new->coordinates = $coordinates; |
||
| 81 | |||
| 82 | return $new; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @param int $limit |
||
| 87 | * |
||
| 88 | * @return ReverseQuery |
||
| 89 | */ |
||
| 90 | public function withLimit(int $limit): self |
||
| 91 | { |
||
| 92 | $new = clone $this; |
||
| 93 | $new->limit = $limit; |
||
| 94 | |||
| 95 | return $new; |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param string $locale |
||
| 100 | * |
||
| 101 | * @return ReverseQuery |
||
| 102 | */ |
||
| 103 | public function withLocale(string $locale): self |
||
| 104 | { |
||
| 105 | $new = clone $this; |
||
| 106 | $new->locale = $locale; |
||
| 107 | |||
| 108 | return $new; |
||
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @param string $name |
||
| 113 | * @param mixed $value |
||
| 114 | * |
||
| 115 | * @return ReverseQuery |
||
| 116 | */ |
||
| 117 | public function withData(string $name, $value): self |
||
| 118 | { |
||
| 119 | $new = clone $this; |
||
| 120 | $new->data[$name] = $value; |
||
| 121 | |||
| 122 | return $new; |
||
| 123 | } |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @return Coordinates |
||
| 127 | */ |
||
| 128 | public function getCoordinates(): Coordinates |
||
| 129 | { |
||
| 130 | return $this->coordinates; |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @return int |
||
| 135 | */ |
||
| 136 | public function getLimit(): int |
||
| 137 | { |
||
| 138 | return $this->limit; |
||
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @return string |
||
|
0 ignored issues
–
show
|
|||
| 143 | */ |
||
| 144 | public function getLocale() |
||
| 145 | { |
||
| 146 | return $this->locale; |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @param string $name |
||
| 151 | * @param mixed|null $default |
||
| 152 | * |
||
| 153 | * @return mixed |
||
| 154 | */ |
||
| 155 | public function getData(string $name, $default = null) |
||
| 156 | { |
||
| 157 | if (!array_key_exists($name, $this->data)) { |
||
| 158 | return $default; |
||
| 159 | } |
||
| 160 | |||
| 161 | return $this->data[$name]; |
||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @return array |
||
| 166 | */ |
||
| 167 | public function getAllData(): array |
||
| 168 | { |
||
| 169 | return $this->data; |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * String for logging. This is also a unique key for the query |
||
| 174 | * |
||
| 175 | * @return string |
||
| 176 | */ |
||
| 177 | public function __toString() |
||
| 178 | { |
||
| 179 | return sprintf('ReverseQuery: %s', json_encode([ |
||
| 180 | 'lat' => $this->getCoordinates()->getLatitude(), |
||
| 181 | 'lng' => $this->getCoordinates()->getLongitude(), |
||
| 182 | 'locale' => $this->getLocale(), |
||
| 183 | 'limit' => $this->getLimit(), |
||
| 184 | 'data' => $this->getAllData(), |
||
| 185 | ])); |
||
| 186 | } |
||
| 187 | } |
||
| 188 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.