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 | namespace Maps\SemanticMW; |
||
6 | |||
7 | use DataValues\Geo\Values\LatLongValue; |
||
8 | use InvalidArgumentException; |
||
9 | use Maps\GeoFunctions; |
||
10 | use Maps\Presentation\MapsDistanceParser; |
||
11 | use SMW\DataValueFactory; |
||
12 | use SMW\DIProperty; |
||
13 | use SMW\Query\Language\ValueDescription; |
||
14 | use SMWDataItem; |
||
15 | use SMWDIGeoCoord; |
||
16 | use SMWThingDescription; |
||
17 | use Wikimedia\Rdbms\IDatabase; |
||
18 | |||
19 | /** |
||
20 | * Description of a geographical area defined by a coordinates set and a distance to the bounds. |
||
21 | * The bounds are a 'rectangle' (but bend due to the earths curvature), as the resulting query |
||
22 | * would otherwise be to resource intensive. |
||
23 | * |
||
24 | * @licence GNU GPL v2+ |
||
25 | * @author Jeroen De Dauw < [email protected] > |
||
26 | */ |
||
27 | class AreaDescription extends ValueDescription { |
||
28 | |||
29 | /** |
||
30 | * @var SMWDIGeoCoord |
||
31 | */ |
||
32 | private $center; |
||
33 | |||
34 | private $radius; |
||
35 | |||
36 | 4 | public function __construct( SMWDataItem $areaCenter, int $comparator, string $radius, DIProperty $property = null ) { |
|
37 | 4 | if ( !( $areaCenter instanceof SMWDIGeoCoord ) ) { |
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
38 | throw new InvalidArgumentException( '$areaCenter needs to be a SMWDIGeoCoord' ); |
||
39 | } |
||
40 | |||
41 | 4 | parent::__construct( $areaCenter, $property, $comparator ); |
|
42 | |||
43 | 4 | $this->center = $areaCenter; |
|
44 | 4 | $this->radius = $radius; |
|
45 | 4 | } |
|
46 | |||
47 | /** |
||
48 | * @see Description::prune |
||
49 | */ |
||
50 | public function prune( &$maxsize, &$maxdepth, &$log ) { |
||
51 | if ( ( $maxsize < $this->getSize() ) || ( $maxdepth < $this->getDepth() ) ) { |
||
52 | $log[] = $this->getQueryString(); |
||
53 | |||
54 | $result = new SMWThingDescription(); |
||
55 | $result->setPrintRequests( $this->getPrintRequests() ); |
||
56 | |||
57 | return $result; |
||
58 | } |
||
59 | |||
60 | $maxsize = $maxsize - $this->getSize(); |
||
61 | $maxdepth = $maxdepth - $this->getDepth(); |
||
62 | |||
63 | return $this; |
||
64 | } |
||
65 | |||
66 | 1 | public function getQueryString( $asValue = false ) { |
|
67 | 1 | $centerString = DataValueFactory::getInstance()->newDataValueByItem( |
|
68 | 1 | $this->center, |
|
69 | 1 | $this->getProperty() |
|
70 | 1 | )->getWikiValue(); |
|
71 | |||
72 | 1 | $queryString = "$centerString ({$this->radius})"; |
|
73 | |||
74 | 1 | return $asValue ? $queryString : "[[$queryString]]"; |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * @see SomePropertyInterpreter::mapValueDescription |
||
79 | * |
||
80 | * FIXME: store specific code should be in the store component |
||
81 | * |
||
82 | * @param string $tableName |
||
83 | * @param string[] $fieldNames |
||
84 | * @param IDatabase $db |
||
85 | * |
||
86 | * @return string|false |
||
87 | */ |
||
88 | 2 | public function getSQLCondition( $tableName, array $fieldNames, IDatabase $db ) { |
|
89 | 2 | if ( $this->center->getDIType() != SMWDataItem::TYPE_GEO ) { |
|
90 | throw new \LogicException( 'Constructor should have prevented this' ); |
||
91 | } |
||
92 | |||
93 | 2 | if ( !$this->comparatorIsSupported() ) { |
|
94 | 1 | return false; |
|
95 | } |
||
96 | |||
97 | 1 | $bounds = $this->getBoundingBox(); |
|
98 | |||
99 | 1 | $north = $db->addQuotes( $bounds['north'] ); |
|
100 | 1 | $east = $db->addQuotes( $bounds['east'] ); |
|
101 | 1 | $south = $db->addQuotes( $bounds['south'] ); |
|
102 | 1 | $west = $db->addQuotes( $bounds['west'] ); |
|
103 | |||
104 | 1 | $isEq = $this->getComparator() == SMW_CMP_EQ; |
|
105 | |||
106 | 1 | $smallerThen = $isEq ? '<' : '>='; |
|
107 | 1 | $biggerThen = $isEq ? '>' : '<='; |
|
108 | 1 | $joinCond = $isEq ? 'AND' : 'OR'; |
|
109 | |||
110 | 1 | $conditions = []; |
|
111 | |||
112 | 1 | $conditions[] = "{$tableName}.$fieldNames[1] $smallerThen $north"; |
|
113 | 1 | $conditions[] = "{$tableName}.$fieldNames[1] $biggerThen $south"; |
|
114 | 1 | $conditions[] = "{$tableName}.$fieldNames[2] $smallerThen $east"; |
|
115 | 1 | $conditions[] = "{$tableName}.$fieldNames[2] $biggerThen $west"; |
|
116 | |||
117 | 1 | return implode( " $joinCond ", $conditions ); |
|
118 | } |
||
119 | |||
120 | 2 | private function comparatorIsSupported(): bool { |
|
121 | 2 | return $this->getComparator() === SMW_CMP_EQ || $this->getComparator() === SMW_CMP_NEQ; |
|
122 | } |
||
123 | |||
124 | /** |
||
125 | * @return float[] An associative array containing the limits with keys north, east, south and west. |
||
126 | */ |
||
127 | 2 | public function getBoundingBox(): array { |
|
128 | 2 | $center = new LatLongValue( |
|
129 | 2 | $this->center->getLatitude(), |
|
130 | 2 | $this->center->getLongitude() |
|
131 | ); |
||
132 | |||
133 | 2 | $radiusInMeters = MapsDistanceParser::parseDistance( $this->radius ); // TODO: this can return false |
|
134 | |||
135 | 2 | $north = GeoFunctions::findDestination( $center, 0, $radiusInMeters ); |
|
0 ignored issues
–
show
It seems like
$radiusInMeters defined by \Maps\Presentation\MapsD...Distance($this->radius) on line 133 can also be of type false ; however, Maps\GeoFunctions::findDestination() does only seem to accept double , did you maybe forget to handle an error condition?
This check looks for type mismatches where the missing type is Consider the follow example <?php
function getDate($date)
{
if ($date !== null) {
return new DateTime($date);
}
return false;
}
This function either returns a new
Loading history...
|
|||
136 | 2 | $east = GeoFunctions::findDestination( $center, 90, $radiusInMeters ); |
|
0 ignored issues
–
show
It seems like
$radiusInMeters defined by \Maps\Presentation\MapsD...Distance($this->radius) on line 133 can also be of type false ; however, Maps\GeoFunctions::findDestination() does only seem to accept double , did you maybe forget to handle an error condition?
This check looks for type mismatches where the missing type is Consider the follow example <?php
function getDate($date)
{
if ($date !== null) {
return new DateTime($date);
}
return false;
}
This function either returns a new
Loading history...
|
|||
137 | 2 | $south = GeoFunctions::findDestination( $center, 180, $radiusInMeters ); |
|
0 ignored issues
–
show
It seems like
$radiusInMeters defined by \Maps\Presentation\MapsD...Distance($this->radius) on line 133 can also be of type false ; however, Maps\GeoFunctions::findDestination() does only seem to accept double , did you maybe forget to handle an error condition?
This check looks for type mismatches where the missing type is Consider the follow example <?php
function getDate($date)
{
if ($date !== null) {
return new DateTime($date);
}
return false;
}
This function either returns a new
Loading history...
|
|||
138 | 2 | $west = GeoFunctions::findDestination( $center, 270, $radiusInMeters ); |
|
0 ignored issues
–
show
It seems like
$radiusInMeters defined by \Maps\Presentation\MapsD...Distance($this->radius) on line 133 can also be of type false ; however, Maps\GeoFunctions::findDestination() does only seem to accept double , did you maybe forget to handle an error condition?
This check looks for type mismatches where the missing type is Consider the follow example <?php
function getDate($date)
{
if ($date !== null) {
return new DateTime($date);
}
return false;
}
This function either returns a new
Loading history...
|
|||
139 | |||
140 | return [ |
||
141 | 2 | 'north' => $north['lat'], |
|
142 | 2 | 'east' => $east['lon'], |
|
143 | 2 | 'south' => $south['lat'], |
|
144 | 2 | 'west' => $west['lon'], |
|
145 | ]; |
||
146 | } |
||
147 | |||
148 | } |
||
149 |