Skip to content

Commit cf961a9

Browse files
committed
added regression tests
1 parent d7490b7 commit cf961a9

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -900,4 +900,11 @@ public function testNarrowSuperglobals(): void
900900
$this->analyse([__DIR__ . '/data/narrow-superglobal.php'], []);
901901
}
902902

903+
public function testBug11602(): void
904+
{
905+
$this->reportPossiblyNonexistentGeneralArrayOffset = true;
906+
907+
$this->analyse([__DIR__ . '/data/bug-11602.php'], []);
908+
}
909+
903910
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Bug11602;
4+
5+
class HelloWorld
6+
{
7+
public function parseRef(string $coordinate, string $ref): string
8+
{
9+
if (preg_match('/^([A-Z]{1,3})([0-9]{1,7})(:([A-Z]{1,3})([0-9]{1,7}))?$/', $ref, $matches) !== 1) {
10+
return $ref;
11+
}
12+
if (!isset($matches[3])) { // single cell, not range
13+
return $coordinate;
14+
}
15+
$minRow = (int) $matches[2];
16+
$maxRow = (int) $matches[5];
17+
$rows = $maxRow - $minRow + 1;
18+
$minCol = $matches[1];
19+
$maxCol = $matches[4];
20+
21+
return "$minCol$minRow:$maxCol$maxRow";
22+
}
23+
}

0 commit comments

Comments
 (0)