Issues (16)

Security Analysis    no request data  

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.

src/Polyline.php (3 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
declare(strict_types=1);
4
5
namespace Location;
6
7
use Location\Distance\DistanceInterface;
8
use Location\Exception\InvalidGeometryException;
9
use Location\Formatter\Polyline\FormatterInterface;
10
11
/**
12
 * Polyline Implementation
13
 *
14
 * @author Marcus Jaschen <[email protected]>
15
 */
16
class Polyline implements GeometryInterface
17
{
18
    use GetBoundsTrait;
19
20
    /**
21
     * @var Coordinate[]
22
     */
23
    protected $points = [];
24
25
    /**
26
     * @param Coordinate $point
27
     *
28
     * @return void
29
     */
30
    public function addPoint(Coordinate $point): void
31
    {
32
        $this->points[] = $point;
33
    }
34
35
    /**
36
     * @param array $points
37
     */
38
    public function addPoints(array $points): void
39
    {
40
        foreach ($points as $point) {
41
            $this->addPoint($point);
42
        }
43
    }
44
45
    /**
46
     * Adds an unique point to the polyline. A maximum allowed distance for
47
     * same point comparison can be provided. Default allowed distance
48
     * deviation is 0.001 meters (1 millimeter).
49
     *
50
     * @param Coordinate $point
51
     * @param float $allowedDistance
52
     *
53
     * @return void
54
     */
55
    public function addUniquePoint(Coordinate $point, float $allowedDistance = .001): void
56
    {
57
        if ($this->containsPoint($point, $allowedDistance)) {
58
            return;
59
        }
60
61
        $this->addPoint($point);
62
    }
63
64
    /**
65
     * @return Coordinate[]
66
     */
67
    public function getPoints(): array
68
    {
69
        return $this->points;
70
    }
71
72
    /**
73
     * @return int
74
     */
75
    public function getNumberOfPoints(): int
76
    {
77
        return count($this->points);
78
    }
79
80
    /**
81
     * @param Coordinate $point
82
     * @param float $allowedDistance
83
     *
84
     * @return bool
85
     */
86
    public function containsPoint(Coordinate $point, float $allowedDistance = .001): bool
87
    {
88
        foreach ($this->points as $existingPoint) {
89
            if ($existingPoint->hasSameLocation($point, $allowedDistance)) {
90
                return true;
91
            }
92
        }
93
94
        return false;
95
    }
96
97
    /**
98
     * @param FormatterInterface $formatter
99
     *
100
     * @return string
101
     */
102
    public function format(FormatterInterface $formatter): string
103
    {
104
        return $formatter->format($this);
105
    }
106
107
    /**
108
     * @return Line[]
109
     */
110
    public function getSegments(): array
111
    {
112
        $length = count($this->points);
113
        $segments = [];
114
115
        if ($length <= 1) {
116
            return $segments;
117
        }
118
119 View Code Duplication
        for ($i = 1; $i < $length; $i++) {
0 ignored issues
show
This code seems to be duplicated across your project.

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.

Loading history...
120
            $segments[] = new Line($this->points[$i - 1], $this->points[$i]);
121
        }
122
123
        return $segments;
124
    }
125
126
    /**
127
     * Calculates the length of the polyline.
128
     *
129
     * @param DistanceInterface $calculator instance of distance calculation class
130
     *
131
     * @return float
132
     */
133 View Code Duplication
    public function getLength(DistanceInterface $calculator): float
0 ignored issues
show
This method seems to be duplicated in your project.

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.

Loading history...
134
    {
135
        $distance = 0.0;
136
137
        if (count($this->points) <= 1) {
138
            return $distance;
139
        }
140
141
        foreach ($this->getSegments() as $segment) {
142
            $distance += $segment->getLength($calculator);
143
        }
144
145
        return $distance;
146
    }
147
148
    /**
149
     * Create a new polyline with reversed order of points, i. e. reversed
150
     * polyline direction.
151
     *
152
     * @return Polyline
153
     */
154 View Code Duplication
    public function getReverse(): Polyline
0 ignored issues
show
This method seems to be duplicated in your project.

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.

Loading history...
155
    {
156
        $reversed = new self();
157
158
        foreach (array_reverse($this->points) as $point) {
159
            $reversed->addPoint($point);
160
        }
161
162
        return $reversed;
163
    }
164
165
    /**
166
     * Returns the point which is defined by the avarages of all
167
     * latitude/longitude values.
168
     *
169
     * This currently only works for polylines which don't cross the dateline at
170
     * 180/-180 degrees longitude.
171
     *
172
     * @return Coordinate
173
     *
174
     * @throws InvalidGeometryException when the polyline doesn't contain any points.
175
     */
176
    public function getAveragePoint(): Coordinate
177
    {
178
        $latitude = 0.0;
179
        $longitude = 0.0;
180
        $numberOfPoints = count($this->points);
181
182
        if ($this->getNumberOfPoints() === 0) {
183
            throw new InvalidGeometryException('Polyline doesn\'t contain points', 9464188927);
184
        }
185
186
        foreach ($this->points as $point) {
187
            /* @var $point Coordinate */
188
            $latitude += $point->getLat();
189
            $longitude += $point->getLng();
190
        }
191
192
        $latitude /= $numberOfPoints;
193
        $longitude /= $numberOfPoints;
194
195
        return new Coordinate($latitude, $longitude);
196
    }
197
}
198