Ysurac /
FlightAirMap
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 | * WKT (Well Known Text) Adapter |
||
| 4 | */ |
||
| 5 | class WKT extends GeoAdapter |
||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Read WKT string into geometry objects |
||
| 10 | * |
||
| 11 | * @param string $WKT A WKT string |
||
|
0 ignored issues
–
show
|
|||
| 12 | * |
||
| 13 | * @return Geometry |
||
| 14 | */ |
||
| 15 | public function read($wkt) { |
||
| 16 | $wkt = trim($wkt); |
||
| 17 | |||
| 18 | // If it contains a ';', then it contains additional SRID data |
||
| 19 | if (strpos($wkt,';')) { |
||
| 20 | $parts = explode(';', $wkt); |
||
| 21 | $wkt = $parts[1]; |
||
| 22 | $eparts = explode('=',$parts[0]); |
||
| 23 | $srid = $eparts[1]; |
||
| 24 | } |
||
| 25 | else { |
||
| 26 | $srid = NULL; |
||
| 27 | } |
||
| 28 | |||
| 29 | // If geos is installed, then we take a shortcut and let it parse the WKT |
||
| 30 | if (geoPHP::geosInstalled()) { |
||
| 31 | $reader = new GEOSWKTReader(); |
||
| 32 | if ($srid) { |
||
| 33 | $geom = geoPHP::geosToGeometry($reader->read($wkt)); |
||
| 34 | $geom->setSRID($srid); |
||
| 35 | return $geom; |
||
| 36 | } |
||
| 37 | else { |
||
| 38 | return geoPHP::geosToGeometry($reader->read($wkt)); |
||
| 39 | } |
||
| 40 | } |
||
| 41 | $wkt = str_replace(', ', ',', $wkt); |
||
| 42 | |||
| 43 | // For each geometry type, check to see if we have a match at the |
||
| 44 | // beggining of the string. If we do, then parse using that type |
||
| 45 | foreach (geoPHP::geometryList() as $geom_type) { |
||
| 46 | $wkt_geom = strtoupper($geom_type); |
||
| 47 | if (strtoupper(substr($wkt, 0, strlen($wkt_geom))) == $wkt_geom) { |
||
| 48 | $data_string = $this->getDataString($wkt); |
||
| 49 | $method = 'parse'.$geom_type; |
||
| 50 | |||
| 51 | if ($srid) { |
||
| 52 | $geom = $this->$method($data_string); |
||
| 53 | $geom->setSRID($srid); |
||
| 54 | return $geom; |
||
| 55 | } |
||
| 56 | else { |
||
| 57 | return $this->$method($data_string); |
||
| 58 | } |
||
| 59 | |||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | private function parsePoint($data_string) { |
||
| 65 | $data_string = $this->trimParens($data_string); |
||
| 66 | $parts = explode(' ',$data_string); |
||
| 67 | return new Point($parts[0], $parts[1]); |
||
| 68 | } |
||
| 69 | |||
| 70 | private function parseLineString($data_string) { |
||
| 71 | $data_string = $this->trimParens($data_string); |
||
| 72 | |||
| 73 | // If it's marked as empty, then return an empty line |
||
| 74 | if ($data_string == 'EMPTY') return new LineString(); |
||
| 75 | |||
| 76 | $parts = explode(',',$data_string); |
||
| 77 | $points = array(); |
||
| 78 | foreach ($parts as $part) { |
||
| 79 | $points[] = $this->parsePoint($part); |
||
| 80 | } |
||
| 81 | return new LineString($points); |
||
| 82 | } |
||
| 83 | |||
| 84 | private function parsePolygon($data_string) { |
||
| 85 | $data_string = $this->trimParens($data_string); |
||
| 86 | |||
| 87 | // If it's marked as empty, then return an empty polygon |
||
| 88 | if ($data_string == 'EMPTY') return new Polygon(); |
||
| 89 | |||
| 90 | $parts = explode('),(',$data_string); |
||
| 91 | $lines = array(); |
||
| 92 | foreach ($parts as $part) { |
||
| 93 | if (!$this->beginsWith($part,'(')) $part = '(' . $part; |
||
| 94 | if (!$this->endsWith($part,')')) $part = $part . ')'; |
||
| 95 | $lines[] = $this->parseLineString($part); |
||
| 96 | } |
||
| 97 | return new Polygon($lines); |
||
| 98 | } |
||
| 99 | |||
| 100 | private function parseMultiPoint($data_string) { |
||
| 101 | $data_string = $this->trimParens($data_string); |
||
| 102 | |||
| 103 | // If it's marked as empty, then return an empty MutiPoint |
||
| 104 | if ($data_string == 'EMPTY') return new MultiPoint(); |
||
| 105 | |||
| 106 | $parts = explode(',',$data_string); |
||
| 107 | $points = array(); |
||
| 108 | foreach ($parts as $part) { |
||
| 109 | $points[] = $this->parsePoint($part); |
||
| 110 | } |
||
| 111 | return new MultiPoint($points); |
||
| 112 | } |
||
| 113 | |||
| 114 | private function parseMultiLineString($data_string) { |
||
| 115 | $data_string = $this->trimParens($data_string); |
||
| 116 | |||
| 117 | // If it's marked as empty, then return an empty multi-linestring |
||
| 118 | if ($data_string == 'EMPTY') return new MultiLineString(); |
||
| 119 | |||
| 120 | $parts = explode('),(',$data_string); |
||
| 121 | $lines = array(); |
||
| 122 | foreach ($parts as $part) { |
||
| 123 | // Repair the string if the explode broke it |
||
| 124 | if (!$this->beginsWith($part,'(')) $part = '(' . $part; |
||
| 125 | if (!$this->endsWith($part,')')) $part = $part . ')'; |
||
| 126 | $lines[] = $this->parseLineString($part); |
||
| 127 | } |
||
| 128 | return new MultiLineString($lines); |
||
| 129 | } |
||
| 130 | |||
| 131 | private function parseMultiPolygon($data_string) { |
||
| 132 | $data_string = $this->trimParens($data_string); |
||
| 133 | |||
| 134 | // If it's marked as empty, then return an empty multi-polygon |
||
| 135 | if ($data_string == 'EMPTY') return new MultiPolygon(); |
||
| 136 | |||
| 137 | $parts = explode(')),((',$data_string); |
||
| 138 | $polys = array(); |
||
| 139 | foreach ($parts as $part) { |
||
| 140 | // Repair the string if the explode broke it |
||
| 141 | if (!$this->beginsWith($part,'((')) $part = '((' . $part; |
||
| 142 | if (!$this->endsWith($part,'))')) $part = $part . '))'; |
||
| 143 | $polys[] = $this->parsePolygon($part); |
||
| 144 | } |
||
| 145 | return new MultiPolygon($polys); |
||
| 146 | } |
||
| 147 | |||
| 148 | private function parseGeometryCollection($data_string) { |
||
| 149 | $data_string = $this->trimParens($data_string); |
||
| 150 | |||
| 151 | // If it's marked as empty, then return an empty geom-collection |
||
| 152 | if ($data_string == 'EMPTY') return new GeometryCollection(); |
||
| 153 | |||
| 154 | $geometries = array(); |
||
| 155 | $matches = array(); |
||
|
0 ignored issues
–
show
$matches is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 156 | $str = preg_replace('/,\s*([A-Za-z])/', '|$1', $data_string); |
||
| 157 | $components = explode('|', trim($str)); |
||
| 158 | |||
| 159 | foreach ($components as $component) { |
||
| 160 | $geometries[] = $this->read($component); |
||
| 161 | } |
||
| 162 | return new GeometryCollection($geometries); |
||
| 163 | } |
||
| 164 | |||
| 165 | protected function getDataString($wkt) { |
||
| 166 | $first_paren = strpos($wkt, '('); |
||
| 167 | |||
| 168 | if ($first_paren !== FALSE) { |
||
| 169 | return substr($wkt, $first_paren); |
||
| 170 | } |
||
| 171 | return FALSE; |
||
| 172 | } |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Trim the parenthesis and spaces |
||
| 176 | */ |
||
| 177 | protected function trimParens($str) { |
||
| 178 | $str = trim($str); |
||
| 179 | |||
| 180 | // We want to only strip off one set of parenthesis |
||
| 181 | if ($this->beginsWith($str, '(')) { |
||
| 182 | return substr($str,1,-1); |
||
| 183 | } |
||
| 184 | else return $str; |
||
| 185 | } |
||
| 186 | |||
| 187 | protected function beginsWith($str, $char) { |
||
| 188 | if (substr($str,0,strlen($char)) == $char) return TRUE; |
||
| 189 | else return FALSE; |
||
| 190 | } |
||
| 191 | |||
| 192 | protected function endsWith($str, $char) { |
||
| 193 | if (substr($str,(0 - strlen($char))) == $char) return TRUE; |
||
| 194 | else return FALSE; |
||
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Serialize geometries into a WKT string. |
||
| 199 | * |
||
| 200 | * @param Geometry $geometry |
||
| 201 | * |
||
| 202 | * @return string The WKT string representation of the input geometries |
||
| 203 | */ |
||
| 204 | public function write(Geometry $geometry) { |
||
| 205 | // If geos is installed, then we take a shortcut and let it write the WKT |
||
| 206 | if (geoPHP::geosInstalled()) { |
||
| 207 | $writer = new GEOSWKTWriter(); |
||
| 208 | $writer->setTrim(TRUE); |
||
| 209 | return $writer->write($geometry->geos()); |
||
| 210 | } |
||
| 211 | |||
| 212 | if ($geometry->isEmpty()) { |
||
| 213 | return strtoupper($geometry->geometryType()).' EMPTY'; |
||
| 214 | } |
||
| 215 | else if ($data = $this->extractData($geometry)) { |
||
| 216 | return strtoupper($geometry->geometryType()).' ('.$data.')'; |
||
| 217 | } |
||
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Extract geometry to a WKT string |
||
| 222 | * |
||
| 223 | * @param Geometry $geometry A Geometry object |
||
| 224 | * |
||
| 225 | * @return string |
||
| 226 | */ |
||
| 227 | public function extractData($geometry) { |
||
| 228 | $parts = array(); |
||
| 229 | switch ($geometry->geometryType()) { |
||
| 230 | case 'Point': |
||
| 231 | return $geometry->getX().' '.$geometry->getY(); |
||
| 232 | case 'LineString': |
||
| 233 | foreach ($geometry->getComponents() as $component) { |
||
|
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Geometry as the method getComponents() does only exist in the following sub-classes of Geometry: Collection, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Polygon. Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
| 234 | $parts[] = $this->extractData($component); |
||
| 235 | } |
||
| 236 | return implode(', ', $parts); |
||
| 237 | case 'Polygon': |
||
| 238 | case 'MultiPoint': |
||
| 239 | case 'MultiLineString': |
||
| 240 | case 'MultiPolygon': |
||
| 241 | foreach ($geometry->getComponents() as $component) { |
||
|
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Geometry as the method getComponents() does only exist in the following sub-classes of Geometry: Collection, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Polygon. Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
| 242 | $parts[] = '('.$this->extractData($component).')'; |
||
| 243 | } |
||
| 244 | return implode(', ', $parts); |
||
| 245 | case 'GeometryCollection': |
||
| 246 | foreach ($geometry->getComponents() as $component) { |
||
|
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Geometry as the method getComponents() does only exist in the following sub-classes of Geometry: Collection, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Polygon. Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
| 247 | $parts[] = strtoupper($component->geometryType()).' ('.$this->extractData($component).')'; |
||
| 248 | } |
||
| 249 | return implode(', ', $parts); |
||
| 250 | } |
||
| 251 | } |
||
| 252 | } |
||
| 253 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.