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/NumericEnsurance.php (2 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
namespace Dgame\Ensurance;
4
5
defined('PHP_FLOAT_EPSILON') or define('PHP_FLOAT_EPSILON', 2.2204460492503e-16);
6
7
/**
8
 * Class NumericEnsurance
9
 * @package Dgame\Ensurance
10
 */
11
final class NumericEnsurance implements EnsuranceInterface
12
{
13
    use EnsuranceTrait;
14
15
    /**
16
     * NumericEnsurance constructor.
17
     *
18
     * @param EnsuranceInterface $ensurance
19
     */
20
    public function __construct(EnsuranceInterface $ensurance)
21
    {
22
        $this->transferEnsurance($ensurance);
23
    }
24
25
    /**
26
     * @return NumericEnsurance
27
     */
28
    public function isInt(): self
29 12
    {
30
        $this->ensure(is_int($this->value))->orThrow('"%s" is not an int', $this->value);
31 12
32
        return $this;
33
    }
34
35 12
    /**
36 12
     * @return NumericEnsurance
37
     */
38
    public function isFloat(): self
39
    {
40
        $this->ensure(is_float($this->value))->orThrow('"%s" is not a float', $this->value);
41 1
42
        return $this;
43 1
    }
44
45 1
    /**
46
     * @param float $value
47
     *
48
     * @return NumericEnsurance
49
     */
50
    public function isGreaterThan(float $value): self
51 1
    {
52
        $this->ensure($this->value > $value)->orThrow('"%s" is not greater than "%s"', $this->value, $value);
53 1
54
        return $this;
55 1
    }
56
57
    /**
58
     * @param float $value
59
     *
60
     * @return NumericEnsurance
61
     */
62
    public function isGreaterThanOrEqualTo(float $value): self
63 1
    {
64
        $this->ensure($this->value >= $value)->orThrow('"%s" is not greater or equal than "%s"', $this->value, $value);
65 1
66
        return $this;
67 1
    }
68
69
    /**
70
     * @param float $value
71
     *
72
     * @return NumericEnsurance
73
     */
74
    public function isLessThan(float $value): self
75 1
    {
76
        $this->ensure($this->value < $value)->orThrow('"%s" is greater or equal to "%s"', $this->value, $value);
77 1
78
        return $this;
79 1
    }
80
81
    /**
82
     * @param float $value
83
     *
84
     * @return NumericEnsurance
85
     */
86
    public function isLessThanOrEqualTo(float $value): self
87 2
    {
88
        $this->ensure($this->value <= $value)->orThrow('"%s" is greater than "%s"', $this->value, $value);
89 2
90
        return $this;
91 2
    }
92
93
    /**
94
     * @return NumericEnsurance
0 ignored issues
show
Should the return type not be \self?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
95
     */
96
    public function isPositive(): self
97
    {
98
        return $this->isGreaterThanOrEqualTo(0);
99 1
    }
100
101 1
    /**
102
     * @return NumericEnsurance
0 ignored issues
show
Should the return type not be \self?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
103 1
     */
104
    public function isNegative(): self
105
    {
106
        return $this->isLessThan(0);
107
    }
108
109 1
    /**
110
     * @return NumericEnsurance
111 1
     */
112
    public function isEven(): self
113
    {
114
        $this->ensure(($this->value & 1) === 0)->orThrow('"%s is not even"', $this->value);
115
116
        return $this;
117 1
    }
118
119 1
    /**
120
     * @return NumericEnsurance
121
     */
122
    public function isOdd(): self
123
    {
124
        $this->ensure(($this->value & 1) === 1)->orThrow('"%s is not odd"', $this->value);
125 2
126
        return $this;
127 2
    }
128
129 2
    /**
130
     * @param float $value
131
     *
132
     * @return NumericEnsurance
133
     */
134
    public function isEqualTo(float $value): self
135 1
    {
136
        $this->ensure(abs($this->value - $value) < PHP_FLOAT_EPSILON)->orThrow('"%s" is not equal to "%s"', $this->value, $value);
137 1
138
        return $this;
139 1
    }
140
141
    /**
142
     * @param float $value
143
     *
144
     * @return NumericEnsurance
145
     */
146
    public function isNotEqualTo(float $value): self
147
    {
148
        $this->ensure(abs($this->value - $value) > PHP_FLOAT_EPSILON)->orThrow('"%s" is equal to "%s"', $this->value, $value);
149
150
        return $this;
151
    }
152
153
    /**
154
     * @param float $lhs
155
     * @param float $rhs
156
     *
157
     * @return NumericEnsurance
158
     */
159
    public function isBetween(float $lhs, float $rhs): self
160
    {
161
        $this->ensure($lhs <= $this->value && $rhs >= $this->value)
162
             ->orThrow('"%s" is not between "%s" and "%s"', $this->value, $lhs, $rhs);
163
164
        return $this;
165
    }
166
167
    /**
168
     * @param float $lhs
169
     * @param float $rhs
170
     *
171
     * @return NumericEnsurance
172 1
     */
173
    public function isNotBetween(float $lhs, float $rhs): self
174 1
    {
175 1
        $this->ensure($lhs > $this->value || $rhs < $this->value)
176
             ->orThrow('"%s" is between "%s" and "%s"', $this->value, $lhs, $rhs);
177 1
178
        return $this;
179
    }
180
}