mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #57413 from nextcloud/bugfix/noid/support-native-int-range
fix(controller): Support native int ranges
This commit is contained in:
commit
52cfd57af9
2 changed files with 33 additions and 2 deletions
|
|
@ -55,7 +55,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))>(\|null)?\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
|
||||
|
|
|
|||
|
|
@ -49,6 +49,16 @@ class MiddleController extends BaseController {
|
|||
*/
|
||||
public function test4(int $rangedOne, int $rangedTwo, ?int $rangedThree, ?int $rangedFour) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int<-4, 42> $rangedOne
|
||||
* @param int<min, max> $rangedTwo
|
||||
* @param int<1, 6>|null $rangedThree
|
||||
* @param ?int<-70, -30> $rangedFour
|
||||
* @return void
|
||||
*/
|
||||
public function test5(int $rangedOne, int $rangedTwo, ?int $rangedThree, ?int $rangedFour) {
|
||||
}
|
||||
}
|
||||
|
||||
class EndController extends MiddleController {
|
||||
|
|
@ -227,7 +237,7 @@ class ControllerMethodReflectorTest extends \Test\TestCase {
|
|||
$this->assertFalse($reader->hasAnnotation('Annotation'));
|
||||
}
|
||||
|
||||
public function testRangeDetection(): void {
|
||||
public function testRangeDetectionPsalm(): void {
|
||||
$reader = new ControllerMethodReflector();
|
||||
$reader->reflect('Test\AppFramework\Utility\EndController', 'test4');
|
||||
|
||||
|
|
@ -247,4 +257,25 @@ class ControllerMethodReflectorTest extends \Test\TestCase {
|
|||
$this->assertSame(-70, $rangeInfo3['min']);
|
||||
$this->assertSame(-30, $rangeInfo3['max']);
|
||||
}
|
||||
|
||||
public function testRangeDetectionNative(): void {
|
||||
$reader = new ControllerMethodReflector();
|
||||
$reader->reflect('Test\AppFramework\Utility\EndController', 'test5');
|
||||
|
||||
$rangeInfo1 = $reader->getRange('rangedOne');
|
||||
$this->assertSame(-4, $rangeInfo1['min']);
|
||||
$this->assertSame(42, $rangeInfo1['max']);
|
||||
|
||||
$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…
Reference in a new issue