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/Filter/Floats.php (5 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
 * Defines the DominionEnterprises\Filter\Floats class.
4
 */
5
6
namespace DominionEnterprises\Filter;
7
8
/**
9
 * A collection of filters for floats.
10
 */
11
final class Floats
12
{
13
    /**
14
     * Filters $value to a float strictly.
15
     *
16
     * The return value is the float, as expected by the \DominionEnterprises\Filterer class.
17
     *
18
     * @param string|float $value the value to filter to a float
19
     * @param bool $allowNull Set to true if NULL values are allowed. The filtered result of a NULL value is NULL
20
     * @param int $minValue The minimum acceptable value
21
     * @param int $maxValue The maximum acceptable value
22
     * @param bool $castInts Flag to cast $value to float if it is an integer
23
     *
24
     * @return float|null The filtered value
25
     *
26
     * @see is_numeric
27
     * @throws \InvalidArgumentException if $allowNull is not a boolean
28
     * @throws \InvalidArgumentException if $minValue is not null and not a float
29
     * @throws \InvalidArgumentException if $maxValue is not null and not a float
30
     * @throws \InvalidArgumentException if $castInts is not a boolean
31
     * @throws \Exception if $value does not pass is_numeric
32
     * @throws \Exception if $value is hex format
33
     * @throws \Exception if $value is not a string or float
34
     * @throws \Exception if $value overflow or underflows
35
     * @throws \Exception if $value is less than $minValue
36
     * @throws \Exception if $value is greater than $maxValue
37
     */
38
    public static function filter($value, $allowNull = false, $minValue = null, $maxValue = null, $castInts = false)
39
    {
40 View Code Duplication
        if ($allowNull !== false && $allowNull !== true) {
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...
41
            throw new \InvalidArgumentException('"' . var_export($allowNull, true) . '" $allowNull was not a bool');
42
        }
43
44 View Code Duplication
        if ($minValue !== null && !is_float($minValue)) {
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...
45
            throw new \InvalidArgumentException('"' . var_export($minValue, true) . '" $minValue was not a float');
46
        }
47
48 View Code Duplication
        if ($maxValue !== null && !is_float($maxValue)) {
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...
49
            throw new \InvalidArgumentException('"' . var_export($maxValue, true) . '" $maxValue was not a float');
50
        }
51
52 View Code Duplication
        if ($castInts !== false && $castInts !== true) {
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...
53
            throw new \InvalidArgumentException('"' . var_export($castInts, true) . '" $castInts was not a bool');
54
        }
55
56
        if ($allowNull === true && $value === null) {
57
            return null;
58
        }
59
60
        $valueFloat = null;
0 ignored issues
show
$valueFloat 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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
61
        if (is_float($value)) {
62
            $valueFloat = $value;
63
        } elseif (is_int($value) && $castInts) {
64
            $valueFloat = (float)$value;
65
        } elseif (is_string($value)) {
66
            $value = trim($value);
67
68
            if (!is_numeric($value)) {
69
                throw new \Exception("{$value} does not pass is_numeric");
70
            }
71
72
            $value = strtolower($value);
73
74
            //This is the only case (that we know of) where is_numeric does not return correctly castable float
75
            if (strpos($value, 'x') !== false) {
76
                throw new \Exception("{$value} is hex format");
77
            }
78
79
            $valueFloat = (float)$value;
80
        } else {
81
            throw new \Exception('"' . var_export($value, true) . '" $value is not a string');
82
        }
83
84
        if (is_infinite($valueFloat)) {
85
            throw new \Exception("{$value} overflow");
86
        }
87
88
        if ($minValue !== null && $valueFloat < $minValue) {
89
            throw new \Exception("{$valueFloat} is less than {$minValue}");
90
        }
91
92
        if ($maxValue !== null && $valueFloat > $maxValue) {
93
            throw new \Exception("{$valueFloat} is greater than {$maxValue}");
94
        }
95
96
        return $valueFloat;
97
    }
98
}
99