Issues (8)

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/Vector.php (1 issue)

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
namespace PHP\Math\Vector;
4
5
use InvalidArgumentException;
6
use PHP\Math\BigNumber\BigNumber;
7
8
class Vector extends Tuple
9
{
10
    /**
11
     * Adds the given vector to this vector.
12
     *
13
     * @param Vector $vector The vector to add.
14
     * @return Vector
15
     * @throws InvalidArgumentException Thrown when the given vector is of a different length.
16
     */
17 2
    public function add(Vector $vector)
18
    {
19 2
        if ($this->getSize() != $vector->getSize()) {
20 1
            throw new InvalidArgumentException('Invalid vector provided, should be of the same size.');
21
        }
22
23 1
        foreach ($this as $index => $value) {
24 1
            $this[$index]->add($vector[$index]);
25 1
        }
26
27 1
        return $this;
28
    }
29
30
    /**
31
     * Conjugates the vector. This is an alias of reverse().
32
     */
33 1
    public function conjugate()
34
    {
35 1
        return $this->reverse();
36
    }
37
38
    /**
39
     * Calculates the dot product between this vector and the given vector.
40
     *
41
     * @param Vector $vector The vector to calculate thet dot product with.
42
     * @return float
43
     */
44 3
    public function dotProduct(Vector $vector)
45
    {
46 3
        if ($this->getSize() !== $vector->getSize()) {
47 1
            throw new InvalidArgumentException('Invalid vector provided. The size should be the same.');
48
        }
49
50 2
        $result = new BigNumber();
51
52 2
        for ($i = 0; $i < $this->getSize(); ++$i) {
53 2
            $value = new BigNumber($this[$i]);
54 2
            $value->multiply($vector[$i]);
55
56 2
            $result->add($value);
57 2
        }
58
59 2
        return $result;
60
    }
61
62
	/**
63
	 * Gets the length of the vector.
64
	 *
65
	 * @return float
66
	 */
67 3
    public function getLength()
68
    {
69 3
        return $this->getLengthSquared()->sqrt();
70
    }
71
72
	/**
73
	 * Gets the square of the vector's length.
74
	 *
75
	 * @return float
76
	 */
77 4
    public function getLengthSquared()
78
    {
79 4
        $result = new BigNumber();
80 4
        for ($i = 0; $i < $this->getSize(); $i++) {
81 4
            $pow = new BigNumber($this->getElement($i));
0 ignored issues
show
$this->getElement($i) is of type object<PHP\Math\BigNumber\BigNumber>, but the function expects a integer.

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...
82 4
            $pow->pow(2);
83
84 4
            $result->add($pow);
85 4
        }
86 4
        return $result;
87
    }
88
89
    /**
90
     * Gets the magnitude of the vector. This is an alias of getLength().
91
     *
92
     * @return float
93
     */
94 1
    public function getMagnitude()
95
    {
96 1
        return $this->getLength();
97
    }
98
99
    /**
100
     * Negates this vector. The vector has the same magnitude as before, but its direction is now opposite.
101
     *
102
     * @return Vector
103
     */
104 3
    public function negate()
105
    {
106 3
        for ($i = 0; $i < $this->getSize(); $i++) {
107 3
            $this->getElement($i)->multiply(-1);
108 3
        }
109
110 3
        return $this;
111
    }
112
113
    /**
114
     * Normalizes the vector, making sure the length of the vector is 1 (a unit vector).
115
     *
116
     * @return Vector
117
     */
118 1
    public function normalize()
119
    {
120 1
        $length = $this->getLength();
121
122 1
        for ($i = 0; $i < $this->getSize(); $i++) {
123 1
            $this->getElement($i)->divide($length);
124 1
        }
125
126 1
        return $this;
127
    }
128
129
    /**
130
     * Reverses the sign of the components. This is an alias of negate.
131
     *
132
     * @return Vector
133
     */
134 2
    public function reverse()
135
    {
136 2
        return $this->negate();
137
    }
138
139
    /**
140
     * Scales the vector.
141
     *
142
     * @param float $scale The scale factor.
143
     * @return Vector
144
     */
145 1
    public function scale($scale)
146
    {
147 1
        foreach ($this as $key => $value) {
148 1
            $this[$key]->multiply($scale);
149 1
        }
150
151 1
        return $this;
152
    }
153
154
    /**
155
     * Subtracts the given vector from this vector.
156
     *
157
     * @param Vector $vector The vector to sutbract.
158
     * @return Vector
159
     * @throws InvalidArgumentException Thrown when the given vector is of a different length.
160
     */
161 2
    public function subtract(Vector $vector)
162
    {
163 2
        if ($this->getSize() != $vector->getSize()) {
164 1
            throw new InvalidArgumentException('Invalid vector provided, should be of the same size.');
165
        }
166
167 1
        foreach ($this as $index => $value) {
168 1
            $this[$index]->subtract($vector[$index]);
169 1
        }
170
171 1
        return $this;
172
    }
173
}
174