Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
  • Loading branch information
blizzz committed Feb 27, 2025
commit 6594d7d96d7695567bbc42d882c3bfebfbab97a3
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function reflect($object, string $method) {
// extract type parameter information
preg_match_all('/@param\h+(?P<type>\w+)\h+\$(?P<var>\w+)/', $docs, $matches);
$this->types = array_combine($matches['var'], $matches['type']);
preg_match_all('/@psalm-param\h+(?P<type>\w+)<(?P<rangeMin>(-?\d+|min)),\h*(?P<rangeMax>(-?\d+|max))>\h+\$(?P<var>\w+)/', $docs, $matches);
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);
foreach ($matches['var'] as $index => $varName) {
if ($matches['type'][$index] !== 'int') {
// only int ranges are possible at the moment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ public function test3() {
/**
* @psalm-param int<-4, 42> $rangedOne
* @psalm-param int<min, max> $rangedTwo
* @psalm-param int<1, 6>|null $rangedThree
* @psalm-param ?int<-70, -30> $rangedFour
* @return void
*/
public function test4(int $rangedOne, int $rangedTwo) {
public function test4(int $rangedOne, int $rangedTwo, ?int $rangedThree, ?int $rangedFour) {
}
}

Expand Down Expand Up @@ -239,5 +241,13 @@ public function testRangeDetection(): void {
$rangeInfo2 = $reader->getRange('rangedTwo');
$this->assertSame(PHP_INT_MIN, $rangeInfo2['min']);
$this->assertSame(PHP_INT_MAX, $rangeInfo2['max']);

$rangeInfo3 = $reader->getRange('rangedThree');
$this->assertSame(1, $rangeInfo3['min']);
$this->assertSame(6, $rangeInfo3['max']);

$rangeInfo3 = $reader->getRange('rangedFour');
$this->assertSame(-70, $rangeInfo3['min']);
$this->assertSame(-30, $rangeInfo3['max']);
}
}
Loading