Skip to content

Commit 0881c20

Browse files
committed
feat(AppFramework): extend range check to optional parameters
Now it also applies when a paramater is documtend with a pending |null, but no further unionation is considered. Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent 001b12c commit 0881c20

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/private/AppFramework/Utility/ControllerMethodReflector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function reflect($object, string $method) {
5050
// extract type parameter information
5151
preg_match_all('/@param\h+(?P<type>\w+)\h+\$(?P<var>\w+)/', $docs, $matches);
5252
$this->types = array_combine($matches['var'], $matches['type']);
53-
preg_match_all('/@psalm-param\h+(?P<type>\w+)<(?P<rangeMin>(-?\d+|min)),\h*(?P<rangeMax>(-?\d+|max))>\h+\$(?P<var>\w+)/', $docs, $matches);
53+
preg_match_all('/@psalm-param\h+(?P<type>\w+)<(?P<rangeMin>(-?\d+|min)),\h*(?P<rangeMax>(-?\d+|max))>(\|null)?\h+\$(?P<var>\w+)/', $docs, $matches);
5454
foreach ($matches['var'] as $index => $varName) {
5555
if ($matches['type'][$index] !== 'int') {
5656
// only int ranges are possible at the moment

tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ public function test3() {
4343
/**
4444
* @psalm-param int<-4, 42> $rangedOne
4545
* @psalm-param int<min, max> $rangedTwo
46+
* @psalm-param int<1, 6>|null $rangedThree
4647
* @return void
4748
*/
48-
public function test4(int $rangedOne, int $rangedTwo) {
49+
public function test4(int $rangedOne, int $rangedTwo, int|null $rangedThree) {
4950
}
5051
}
5152

@@ -239,5 +240,9 @@ public function testRangeDetection(): void {
239240
$rangeInfo2 = $reader->getRange('rangedTwo');
240241
$this->assertSame(PHP_INT_MIN, $rangeInfo2['min']);
241242
$this->assertSame(PHP_INT_MAX, $rangeInfo2['max']);
243+
244+
$rangeInfo3 = $reader->getRange('rangedThree');
245+
$this->assertSame(1, $rangeInfo3['min']);
246+
$this->assertSame(6, $rangeInfo3['max']);
242247
}
243248
}

0 commit comments

Comments
 (0)