Issues (843)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

require/libs/geoPHP/lib/geometry/Polygon.class.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * Polygon: A polygon is a plane figure that is bounded by a closed path, 
5
 * composed of a finite sequence of straight line segments
6
 */
7
class Polygon extends Collection
8
{
9
  protected $geom_type = 'Polygon';
10
11
  public function area($exterior_only = FALSE, $signed = FALSE) {
12
    if ($this->isEmpty()) return 0;
13
    
14
    if ($this->geos() && $exterior_only == FALSE) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
15
      return $this->geos()->area();
16
    }
17
    
18
    $exterior_ring = $this->components[0];
19
    $pts = $exterior_ring->getComponents();
20
    
21
    $c = count($pts);
22
    if((int)$c == '0') return NULL;
23
    $a = '0';
24
    foreach($pts as $k => $p){
25
      $j = ($k + 1) % $c;
26
      $a = $a + ($p->getX() * $pts[$j]->getY()) - ($p->getY() * $pts[$j]->getX());
27
    }
28
    
29
    if ($signed) $area = ($a / 2);
30
    else $area = abs(($a / 2));
31
    
32
    if ($exterior_only == TRUE) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
33
      return $area;
34
    }
35
    foreach ($this->components as $delta => $component) {
36
      if ($delta != 0) {
37
        $inner_poly = new Polygon(array($component));
38
        $area -= $inner_poly->area();
39
      }
40
    }
41
    return $area;
42
  }
43
  
44
  public function centroid() {
45
    if ($this->isEmpty()) return NULL;
46
    
47
    if ($this->geos()) {
48
      return geoPHP::geosToGeometry($this->geos()->centroid());
49
    }
50
    
51
    $exterior_ring = $this->components[0];
52
    $pts = $exterior_ring->getComponents();
53
    
54
    $c = count($pts);
55
    if((int)$c == '0') return NULL;
56
    $cn = array('x' => '0', 'y' => '0');
57
    $a = $this->area(TRUE, TRUE);
58
    
59
    // If this is a polygon with no area. Just return the first point.
60
    if ($a == 0) {
61
      return $this->exteriorRing()->pointN(1);
62
    }
63
    
64
    foreach($pts as $k => $p){
65
      $j = ($k + 1) % $c;
66
      $P = ($p->getX() * $pts[$j]->getY()) - ($p->getY() * $pts[$j]->getX());
67
      $cn['x'] = $cn['x'] + ($p->getX() + $pts[$j]->getX()) * $P;
68
      $cn['y'] = $cn['y'] + ($p->getY() + $pts[$j]->getY()) * $P;
69
    }
70
    
71
    $cn['x'] = $cn['x'] / ( 6 * $a);
72
    $cn['y'] = $cn['y'] / ( 6 * $a);
73
    
74
    $centroid = new Point($cn['x'], $cn['y']);
0 ignored issues
show
$cn['y'] is of type integer|double, but the function expects a object<numeric>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
75
    return $centroid;
76
  }
77
78
	/**
79
	 * Find the outermost point from the centroid
80
	 *
81
	 * @returns Point The outermost point
82
	 */
83
  public function outermostPoint() {
84
		$centroid = $this->getCentroid();
85
86
		$max = array('length' => 0, 'point' => null);
87
88
		foreach($this->getPoints() as $point) {
89
			$lineString = new LineString(array($centroid, $point));
90
91
			if($lineString->length() > $max['length']) {
92
				$max['length'] = $lineString->length();
93
				$max['point'] = $point;
94
			}
95
		}
96
97
		return $max['point'];
98
  }
99
100
  public function exteriorRing() {
101
    if ($this->isEmpty()) return new LineString();
102
    return $this->components[0];
103
  }
104
  
105
  public function numInteriorRings() {
106
    if ($this->isEmpty()) return 0;
107
    return $this->numGeometries()-1;
108
  }
109
  
110
  public function interiorRingN($n) {
111
    return $this->geometryN($n+1);
112
  }
113
  
114
  public function dimension() {
115
    if ($this->isEmpty()) return 0;
116
    return 2;
117
  }
118
119
  public function isSimple() {
120
    if ($this->geos()) {
121
      return $this->geos()->isSimple();
122
    }
123
    
124
    $segments = $this->explode();
125
    
126
    foreach ($segments as $i => $segment) {
127
      foreach ($segments as $j => $check_segment) {
128
        if ($i != $j) {
129
          if ($segment->lineSegmentIntersect($check_segment)) {
130
            return FALSE;
131
          }
132
        }
133
      }
134
    }
135
    return TRUE;
136
  }
137
138
  /**
139
   * For a given point, determine whether it's bounded by the given polygon.
140
   * Adapted from http://www.assemblysys.com/dataServices/php_pointinpolygon.php
141
   * @see http://en.wikipedia.org/wiki/Point%5Fin%5Fpolygon
142
   *
143
   * @param Point $point 
144
   * @param boolean $pointOnBoundary - whether a boundary should be considered "in" or not
145
   * @param boolean $pointOnVertex - whether a vertex should be considered "in" or not
146
   * @return boolean
147
   */
148
  public function pointInPolygon($point, $pointOnBoundary = true, $pointOnVertex = true) {
149
    $vertices = $this->getPoints();
150
151
    // Check if the point sits exactly on a vertex
152
    if ($this->pointOnVertex($point, $vertices)) {
0 ignored issues
show
The call to Polygon::pointOnVertex() has too many arguments starting with $vertices.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
153
      return $pointOnVertex ? TRUE : FALSE;
154
    }
155
  
156
    // Check if the point is inside the polygon or on the boundary
157
    $intersections = 0; 
158
    $vertices_count = count($vertices);
159
160
    for ($i=1; $i < $vertices_count; $i++) {
161
      $vertex1 = $vertices[$i-1]; 
162
      $vertex2 = $vertices[$i];
163
      if ($vertex1->y() == $vertex2->y() 
164
      && $vertex1->y() == $point->y() 
165
      && $point->x() > min($vertex1->x(), $vertex2->x()) 
166
      && $point->x() < max($vertex1->x(), $vertex2->x())) {
167
        // Check if point is on an horizontal polygon boundary
168
        return $pointOnBoundary ? TRUE : FALSE;
169
      }
170
      if ($point->y() > min($vertex1->y(), $vertex2->y())
171
      && $point->y() <= max($vertex1->y(), $vertex2->y())
172
      && $point->x() <= max($vertex1->x(), $vertex2->x())
173
      && $vertex1->y() != $vertex2->y()) {
174
        $xinters = 
175
          ($point->y() - $vertex1->y()) * ($vertex2->x() - $vertex1->x())
176
          / ($vertex2->y() - $vertex1->y()) 
177
          + $vertex1->x();
178
        if ($xinters == $point->x()) {
179
          // Check if point is on the polygon boundary (other than horizontal)
180
          return $pointOnBoundary ? TRUE : FALSE;
181
        }
182
        if ($vertex1->x() == $vertex2->x() || $point->x() <= $xinters) {
183
          $intersections++;
184
        }
185
      } 
186
    } 
187
    // If the number of edges we passed through is even, then it's in the polygon.
188
    if ($intersections % 2 != 0) {
189
      return TRUE;
190
    }
191
    else {
192
      return FALSE;
193
    }
194
  }
195
  
196
  public function pointOnVertex($point) {
197
    foreach($this->getPoints() as $vertex) {
198
      if ($point->equals($vertex)) {
199
        return true;
200
      }
201
    }
202
  }
203
204
205
  // Not valid for this geometry type
206
  // --------------------------------
207
  public function length() { return NULL; }
208
  
209
}
210
211