Skip to content

Commit c497d80

Browse files
authored
Merge pull request #8 from dan-on/chore/update-phpstan-to-1.3.x
chore: update phpstan to 1.3.x
2 parents e262753 + 0072f4f commit c497d80

4 files changed

+18
-29
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"require-dev": {
2222
"phpunit/phpunit": "^9",
23-
"phpstan/phpstan": "^0.12.91",
23+
"phpstan/phpstan": "^1.3.3",
2424
"vimeo/psalm": "^4.8",
2525
"phpbench/phpbench": "^1.0",
2626
"squizlabs/php_codesniffer": "^3.6",

tests/Benchmark/CountIntersectionsBench.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Danon\IntervalTree\Tests\Benchmark;
@@ -34,7 +35,7 @@ public function init(): void
3435
$this->bruteForceList = [];
3536

3637
for ($i = 0; $i < self::AMOUNT_INTERVALS_IN_TREE; $i++) {
37-
$interval = $this->generateInterval();
38+
$interval = $this->generateInterval(self::MAX_INTERVAL_HIGH, self::MAX_INTERVAL_OFFSET);
3839
$this->tree->insert($interval);
3940
$this->bruteForceList[] = $interval;
4041
}
@@ -45,7 +46,7 @@ public function init(): void
4546
*/
4647
public function benchTree(): void
4748
{
48-
$searchedInterval = $this->generateInterval();
49+
$searchedInterval = $this->generateInterval(self::MAX_INTERVAL_HIGH, self::MAX_INTERVAL_OFFSET);
4950
$this->tree->countIntersections($searchedInterval);
5051
}
5152

@@ -54,7 +55,7 @@ public function benchTree(): void
5455
*/
5556
public function benchBruteForce(): void
5657
{
57-
$searchedInterval = $this->generateInterval();
58+
$searchedInterval = $this->generateInterval(self::MAX_INTERVAL_HIGH, self::MAX_INTERVAL_OFFSET);
5859
foreach ($this->bruteForceList as $interval) {
5960
$interval->intersect($searchedInterval);
6061
}
+9-6
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Danon\IntervalTree\Tests\Benchmark;
56

67
use Danon\IntervalTree\Interval\NumericInterval;
78
use Exception;
9+
use InvalidArgumentException;
810

911
trait GenerateIntervalTrait
1012
{
1113
/**
14+
* @param int $maxHigh
15+
* @param int $maxOffset
1216
* @return NumericInterval
1317
*/
14-
private function generateInterval(): NumericInterval
18+
private function generateInterval(int $maxHigh, int $maxOffset): NumericInterval
1519
{
1620
try {
17-
$low = random_int(0, self::MAX_INTERVAL_HIGH);
18-
$high = random_int($low, min($low + self::MAX_INTERVAL_OFFSET, self::MAX_INTERVAL_HIGH));
21+
$low = random_int(0, $maxHigh);
22+
$high = random_int($low, min($low + $maxOffset, $maxHigh));
1923
} catch (Exception $exception) {
20-
echo 'Cannot generate interval: ' . $exception->getMessage();
21-
exit;
24+
throw new InvalidArgumentException('Wrong interval arguments', $exception->getCode(), $exception);
2225
}
2326
return new NumericInterval($low, $high);
2427
}
25-
}
28+
}

tests/Benchmark/HasIntersectionBench.php

+4-19
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Danon\IntervalTree\Tests\Benchmark;
56

67
use Danon\IntervalTree\Interval\NumericInterval;
78
use Danon\IntervalTree\IntervalTree;
8-
use Exception;
99
use PhpBench\Benchmark\Metadata\Annotations\Revs;
1010

1111
/**
@@ -35,7 +35,7 @@ public function init(): void
3535
$this->bruteForceList = [];
3636

3737
for ($i = 0; $i < self::AMOUNT_INTERVALS_IN_TREE; $i++) {
38-
$interval = $this->generateInterval();
38+
$interval = $this->generateInterval(self::MAX_INTERVAL_HIGH, self::MAX_INTERVAL_OFFSET);
3939
$this->tree->insert($interval);
4040
$this->bruteForceList[] = $interval;
4141
}
@@ -46,7 +46,7 @@ public function init(): void
4646
*/
4747
public function benchTree(): void
4848
{
49-
$searchedInterval = $this->generateInterval();
49+
$searchedInterval = $this->generateInterval(self::MAX_INTERVAL_HIGH, self::MAX_INTERVAL_OFFSET);
5050
$this->tree->hasIntersection($searchedInterval);
5151
}
5252

@@ -55,26 +55,11 @@ public function benchTree(): void
5555
*/
5656
public function benchBruteForce(): void
5757
{
58-
$searchedInterval = $this->generateInterval();
58+
$searchedInterval = $this->generateInterval(self::MAX_INTERVAL_HIGH, self::MAX_INTERVAL_OFFSET);
5959
foreach ($this->bruteForceList as $interval) {
6060
if ($interval->intersect($searchedInterval)) {
6161
break;
6262
}
6363
}
6464
}
65-
66-
/**
67-
* @return NumericInterval
68-
*/
69-
private function generateInterval(): NumericInterval
70-
{
71-
try {
72-
$low = random_int(0, self::MAX_INTERVAL_HIGH);
73-
$high = random_int($low, min($low + self::MAX_INTERVAL_OFFSET, self::MAX_INTERVAL_HIGH));
74-
} catch (Exception $exception) {
75-
echo 'Cannot generate interval: ' . $exception->getMessage();
76-
exit;
77-
}
78-
return new NumericInterval($low, $high);
79-
}
8065
}

0 commit comments

Comments
 (0)