Issues (4)

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.

test/StdRangesCalculatorTest.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
declare(strict_types = 1);
4
5
namespace Test;
6
7
use Hop\Ranges\Range;
8
use Hop\Ranges\RangesCalculator;
9
use Hop\Ranges\StdRangesCalculator;
10
use PHPUnit\Framework\TestCase;
11
12
final class StdRangesCalculatorTest extends TestCase
13
{
14
    /**
15
     * @var StdRangesCalculator
16
     */
17
    private $calculator;
18
19
    public function setUp()
20
    {
21
        $this->calculator = new StdRangesCalculator();
22
    }
23
24
    public function test_instanceOf(): void
25
    {
26
        $this->assertInstanceOf(RangesCalculator::class, $this->calculator);
27
    }
28
29
    public function test_sumEmpty(): void
30
    {
31
        $this->assertEquals([], $this->calculator->sum());
32
    }
33
34
    public function test_sumNotMerge(): void
35
    {
36
        $ranges = $this->calculator->sum(
37
            new Range(new \DateTime('2018-01-01 00:01:01'), new \DateTime('2018-01-01 00:02:00')),
38
            new Range(new \DateTime('2018-02-01 00:00:00'), new \DateTime('2018-02-01 00:01:00')),
39
            new Range(new \DateTime('2018-01-01 00:00:00'), new \DateTime('2018-01-01 00:01:00'))
40
        );
41
42
        $this->assertCount(3, $ranges);
43
44
        $this->assertEquals('2018-01-01 00:00:00', $ranges[0]->dateFrom()->format('Y-m-d H:i:s'));
45
        $this->assertEquals('2018-01-01 00:01:00', $ranges[0]->dateTo()->format('Y-m-d H:i:s'));
46
47
        $this->assertEquals('2018-01-01 00:01:01', $ranges[1]->dateFrom()->format('Y-m-d H:i:s'));
48
        $this->assertEquals('2018-01-01 00:02:00', $ranges[1]->dateTo()->format('Y-m-d H:i:s'));
49
50
        $this->assertEquals('2018-02-01 00:00:00', $ranges[2]->dateFrom()->format('Y-m-d H:i:s'));
51
        $this->assertEquals('2018-02-01 00:01:00', $ranges[2]->dateTo()->format('Y-m-d H:i:s'));
52
    }
53
54
    public function test_sumAndMerge(): void
55
    {
56
        $ranges = $this->calculator->sum(
57
            new Range(new \DateTime('2018-01-01 00:01:00'), new \DateTime('2018-01-01 00:02:00')),
58
            new Range(new \DateTime('2018-02-01 00:00:00'), new \DateTime('2018-02-01 00:01:00')),
59
            new Range(new \DateTime('2018-01-01 00:00:00'), new \DateTime('2018-01-01 00:01:00'))
60
        );
61
62
        $this->assertCount(2, $ranges);
63
64
        $this->assertEquals('2018-01-01 00:00:00', $ranges[0]->dateFrom()->format('Y-m-d H:i:s'));
65
        $this->assertEquals('2018-01-01 00:02:00', $ranges[0]->dateTo()->format('Y-m-d H:i:s'));
66
67
        $this->assertEquals('2018-02-01 00:00:00', $ranges[1]->dateFrom()->format('Y-m-d H:i:s'));
68
        $this->assertEquals('2018-02-01 00:01:00', $ranges[1]->dateTo()->format('Y-m-d H:i:s'));
69
70
71
        $ranges = $this->calculator->sum(
72
            new Range(new \DateTime('2018-01-01 00:01:00'), new \DateTime('2018-01-01 00:02:00')),
73
            new Range(new \DateTime('2018-01-01 00:01:58'), new \DateTime('2018-02-01 00:01:00')),
74
            new Range(new \DateTime('2018-01-01 00:00:00'), new \DateTime('2018-01-01 00:01:00'))
75
        );
76
77
        $this->assertCount(1, $ranges);
78
79
        $this->assertEquals('2018-01-01 00:00:00', $ranges[0]->dateFrom()->format('Y-m-d H:i:s'));
80
        $this->assertEquals('2018-02-01 00:01:00', $ranges[0]->dateTo()->format('Y-m-d H:i:s'));
81
82
83
        $ranges = $this->calculator->sum(
84
            new Range(new \DateTime('2018-01-01 00:01:00'), new \DateTime('2018-01-01 00:02:00')),
85
            new Range(new \DateTime('2018-01-01 00:01:56'), new \DateTime('2018-01-01 00:01:58')),
86
            new Range(new \DateTime('2018-01-01 00:00:00'), new \DateTime('2018-01-01 00:01:00'))
87
        );
88
89
        $this->assertCount(1, $ranges);
90
91
        $this->assertEquals('2018-01-01 00:00:00', $ranges[0]->dateFrom()->format('Y-m-d H:i:s'));
92
        $this->assertEquals('2018-01-01 00:02:00', $ranges[0]->dateTo()->format('Y-m-d H:i:s'));
93
    }
94
95
    public function test_sumMergeInner(): void
96
    {
97
        $ranges = $this->calculator->sum(
98
            new Range(new \DateTime('2018-01-01 00:01:00'), new \DateTime('2018-01-01 00:02:00')),
99
            new Range(new \DateTime('2018-01-01 00:01:56'), new \DateTime('2018-01-01 00:01:59')),
100
            new Range(new \DateTime('2018-01-01 00:01:57'), new \DateTime('2018-01-01 00:01:58')),
101
            new Range(new \DateTime('2018-01-01 00:00:00'), new \DateTime('2018-01-01 00:01:00'))
102
        );
103
104
        $this->assertCount(1, $ranges);
105
106
        $this->assertEquals('2018-01-01 00:00:00', $ranges[0]->dateFrom()->format('Y-m-d H:i:s'));
107
        $this->assertEquals('2018-01-01 00:02:00', $ranges[0]->dateTo()->format('Y-m-d H:i:s'));
108
    }
109
110
    public function test_subNoEffect(): void
111
    {
112
        $range1 = new Range(new \DateTime('2018-01-01 00:01:00'), new \DateTime('2018-01-01 00:02:00'));
113
        $range2 = new Range(new \DateTime('2018-03-01 00:01:00'), new \DateTime('2018-03-01 00:02:00'));
114
115
        $ranges = $this->calculator->sub($range1, $range2);
116
        $this->assertCount(1, $ranges);
117
        $this->assertEquals($range1->dateFrom()->format('Y-m-d H:i:s'), $ranges[0]->dateFrom()->format('Y-m-d H:i:s'));
118
        $this->assertEquals($range1->dateTo()->format('Y-m-d H:i:s'), $ranges[0]->dateTo()->format('Y-m-d H:i:s'));
119
    }
120
121
    public function test_subInner(): void
122
    {
123
        $range1 = new Range(new \DateTime('2018-01-01 00:01:00'), new \DateTime('2018-02-10 00:01:00'));
124
        $range2 = new Range(new \DateTime('2018-01-10 00:01:00'), new \DateTime('2018-02-03 00:02:00'));
125
126
        $ranges = $this->calculator->sub($range1, $range2);
127
        $this->assertCount(2, $ranges);
128
129
        $this->assertEquals('2018-01-01 00:01:00', $ranges[0]->dateFrom()->format('Y-m-d H:i:s'));
130
        $this->assertEquals('2018-01-10 00:00:59', $ranges[0]->dateTo()->format('Y-m-d H:i:s'));
131
132
        $this->assertEquals('2018-02-03 00:02:01', $ranges[1]->dateFrom()->format('Y-m-d H:i:s'));
133
        $this->assertEquals('2018-02-10 00:01:00', $ranges[1]->dateTo()->format('Y-m-d H:i:s'));
134
135
136
        $range1 = new Range(new \DateTime('2018-01-01 00:01:00'), new \DateTime('2018-02-10 00:01:00'));
137
        $range2 = new Range(new \DateTime('2018-01-10 00:01:00'), new \DateTime('2018-02-03 00:02:00'));
138
        $range3 = new Range(new \DateTime('2018-01-11 00:01:00'), new \DateTime('2018-02-01 00:02:00'));
139
140
        $ranges = $this->calculator->sub($range1, $range2, $range3);
141
        $this->assertCount(2, $ranges);
142
143
        $this->assertEquals('2018-01-01 00:01:00', $ranges[0]->dateFrom()->format('Y-m-d H:i:s'));
144
        $this->assertEquals('2018-01-10 00:00:59', $ranges[0]->dateTo()->format('Y-m-d H:i:s'));
145
146
        $this->assertEquals('2018-02-03 00:02:01', $ranges[1]->dateFrom()->format('Y-m-d H:i:s'));
147
        $this->assertEquals('2018-02-10 00:01:00', $ranges[1]->dateTo()->format('Y-m-d H:i:s'));
148
149
150
        $range1 = new Range(new \DateTime('2018-01-01 00:01:00'), new \DateTime('2018-02-10 00:01:00'));
151
        $range2 = new Range(new \DateTime('2018-01-10 00:01:00'), new \DateTime('2018-02-03 00:02:00'));
152
        $range3 = new Range(new \DateTime('2018-01-11 00:01:00'), new \DateTime('2018-02-04 00:02:00'));
153
154
        $ranges = $this->calculator->sub($range1, $range2, $range3);
155
        $this->assertCount(2, $ranges);
156
157
        $this->assertEquals('2018-01-01 00:01:00', $ranges[0]->dateFrom()->format('Y-m-d H:i:s'));
158
        $this->assertEquals('2018-01-10 00:00:59', $ranges[0]->dateTo()->format('Y-m-d H:i:s'));
159
160
        $this->assertEquals('2018-02-04 00:02:01', $ranges[1]->dateFrom()->format('Y-m-d H:i:s'));
161
        $this->assertEquals('2018-02-10 00:01:00', $ranges[1]->dateTo()->format('Y-m-d H:i:s'));
162
163
164
        $range1 = new Range(new \DateTime('2018-01-01 00:01:00'), new \DateTime('2018-02-10 00:01:00'));
165
        $range2 = new Range(new \DateTime('2018-01-10 00:01:00'), new \DateTime('2018-02-03 00:02:00'));
166
        $range3 = new Range(new \DateTime('2018-01-09 00:01:00'), new \DateTime('2018-02-04 00:02:00'));
167
168
        $ranges = $this->calculator->sub($range1, $range2, $range3);
169
        $this->assertCount(2, $ranges);
170
171
        $this->assertEquals('2018-01-01 00:01:00', $ranges[0]->dateFrom()->format('Y-m-d H:i:s'));
172
        $this->assertEquals('2018-01-09 00:00:59', $ranges[0]->dateTo()->format('Y-m-d H:i:s'));
173
174
        $this->assertEquals('2018-02-04 00:02:01', $ranges[1]->dateFrom()->format('Y-m-d H:i:s'));
175
        $this->assertEquals('2018-02-10 00:01:00', $ranges[1]->dateTo()->format('Y-m-d H:i:s'));
176
177
178
        $range1 = new Range(new \DateTime('2018-01-01 00:01:00'), new \DateTime('2018-02-10 00:01:00'));
179
        $range2 = new Range(new \DateTime('2018-01-10 00:01:00'), new \DateTime('2018-02-03 00:02:00'));
180
        $range3 = new Range(new \DateTime('2018-02-04 00:01:00'), new \DateTime('2018-02-05 00:02:00'));
181
182
        $ranges = $this->calculator->sub($range1, $range2, $range3);
183
        $this->assertCount(3, $ranges);
184
185
        $this->assertEquals('2018-01-01 00:01:00', $ranges[0]->dateFrom()->format('Y-m-d H:i:s'));
186
        $this->assertEquals('2018-01-10 00:00:59', $ranges[0]->dateTo()->format('Y-m-d H:i:s'));
187
188
        $this->assertEquals('2018-02-03 00:02:01', $ranges[1]->dateFrom()->format('Y-m-d H:i:s'));
189
        $this->assertEquals('2018-02-04 00:00:59', $ranges[1]->dateTo()->format('Y-m-d H:i:s'));
190
191
        $this->assertEquals('2018-02-05 00:02:01', $ranges[2]->dateFrom()->format('Y-m-d H:i:s'));
192
        $this->assertEquals('2018-02-10 00:01:00', $ranges[2]->dateTo()->format('Y-m-d H:i:s'));
193
    }
194
195 View Code Duplication
    public function test_subLeftSide(): void
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...
196
    {
197
        $range1 = new Range(new \DateTime('2018-01-01 00:01:00'), new \DateTime('2018-01-04 00:02:00'));
198
        $range2 = new Range(new \DateTime('2017-12-30 00:00:00'), new \DateTime('2018-01-03 00:02:00'));
199
200
        $ranges = $this->calculator->sub($range1, $range2);
201
        $this->assertCount(1, $ranges);
202
        $this->assertEquals('2018-01-03 00:02:01', $ranges[0]->dateFrom()->format('Y-m-d H:i:s'));
203
        $this->assertEquals('2018-01-04 00:02:00', $ranges[0]->dateTo()->format('Y-m-d H:i:s'));
204
    }
205
206 View Code Duplication
    public function test_subRightSide(): void
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...
207
    {
208
        $range1 = new Range(new \DateTime('2018-01-01 00:01:00'), new \DateTime('2018-01-04 00:02:00'));
209
        $range2 = new Range(new \DateTime('2018-01-02 00:00:00'), new \DateTime('2018-03-01 00:02:00'));
210
211
        $ranges = $this->calculator->sub($range1, $range2);
212
        $this->assertCount(1, $ranges);
213
        $this->assertEquals('2018-01-01 00:01:00', $ranges[0]->dateFrom()->format('Y-m-d H:i:s'));
214
        $this->assertEquals('2018-01-01 23:59:59', $ranges[0]->dateTo()->format('Y-m-d H:i:s'));
215
    }
216
217
    public function test_subMix(): void
218
    {
219
        $range1 = new Range(new \DateTime('2018-01-01 00:01:00'), new \DateTime('2018-01-04 00:02:00'));
220
        $range2 = new Range(new \DateTime('2018-01-02 00:00:01'), new \DateTime('2018-01-02 00:01:00'));
221
        $range3 = new Range(new \DateTime('2018-01-03 01:00:00'), new \DateTime('2018-02-01 00:00:00'));
222
223
        $ranges = $this->calculator->sub($range1, $range2, $range3);
224
        $this->assertCount(2, $ranges);
225
        $this->assertEquals('2018-01-01 00:01:00', $ranges[0]->dateFrom()->format('Y-m-d H:i:s'));
226
        $this->assertEquals('2018-01-02 00:00:00', $ranges[0]->dateTo()->format('Y-m-d H:i:s'));
227
228
        $this->assertEquals('2018-01-02 00:01:01', $ranges[1]->dateFrom()->format('Y-m-d H:i:s'));
229
        $this->assertEquals('2018-01-03 00:59:59', $ranges[1]->dateTo()->format('Y-m-d H:i:s'));
230
    }
231
232
    public function test_subAll(): void
233
    {
234
        $range1 = new Range(new \DateTime('2018-01-01 00:01:00'), new \DateTime('2018-01-04 00:02:00'));
235
        $range2 = new Range(new \DateTime('2017-12-30 00:00:00'), new \DateTime('2018-03-01 00:02:00'));
236
237
        $ranges = $this->calculator->sub($range1, $range2);
238
        $this->assertCount(0, $ranges);
239
    }
240
}
241