aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2025-02-27 19:11:44 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2025-02-27 19:49:04 +0100
commit6594d7d96d7695567bbc42d882c3bfebfbab97a3 (patch)
tree938c5f345f052dc4a04d3d8cb5d8a881c8b90f9c
parent001b12c482c24d43226afeb4164d0fc410383819 (diff)
downloadnextcloud-server-enh/noid/nullable-range.tar.gz
nextcloud-server-enh/noid/nullable-range.zip
feat(AppFramework): extend range check to optional parametersenh/noid/nullable-range
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>
-rw-r--r--lib/private/AppFramework/Utility/ControllerMethodReflector.php2
-rw-r--r--tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php12
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/private/AppFramework/Utility/ControllerMethodReflector.php b/lib/private/AppFramework/Utility/ControllerMethodReflector.php
index 2031327dfae..679e1788004 100644
--- a/lib/private/AppFramework/Utility/ControllerMethodReflector.php
+++ b/lib/private/AppFramework/Utility/ControllerMethodReflector.php
@@ -50,7 +50,7 @@ class ControllerMethodReflector implements IControllerMethodReflector {
// 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
diff --git a/tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php b/tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php
index e0748d89f7f..00ae4792824 100644
--- a/tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php
+++ b/tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php
@@ -43,9 +43,11 @@ class MiddleController extends BaseController {
/**
* @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) {
}
}
@@ -239,5 +241,13 @@ class ControllerMethodReflectorTest extends \Test\TestCase {
$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']);
}
}