Skip to content

Commit

Permalink
more precise preg_match_all return type on php8
Browse files Browse the repository at this point in the history
  • Loading branch information
clxmstaab authored and ondrejmirtes committed Mar 2, 2022
1 parent 12a76c8 commit 04b9c99
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions resources/functionMap_php80delta.php
Expand Up @@ -85,6 +85,7 @@
'PhpToken::is' => ['bool', 'kind'=>'string|int|string[]|int[]'],
'PhpToken::isIgnorable' => ['bool'],
'PhpToken::getTokenName' => ['string'],
'preg_match_all' => ['0|positive-int|false', 'pattern'=>'string', 'subject'=>'string', '&w_subpatterns='=>'array', 'flags='=>'int', 'offset='=>'int'],
'proc_get_status' => ['array{command: string, pid: int, running: bool, signaled: bool, stopped: bool, exitcode: int, termsig: int, stopsig: int}', 'process'=>'resource'],
'set_error_handler' => ['?callable', 'callback'=>'null|callable(int,string,string,int):bool', 'error_types='=>'int'],
'socket_addrinfo_lookup' => ['AddressInfo[]', 'node'=>'string', 'service='=>'mixed', 'hints='=>'array'],
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Expand Up @@ -722,6 +722,12 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/callable-in-union.php');
}

if (PHP_VERSION_ID < 80000) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/preg_match_php7.php');
} else {
yield from $this->gatherAssertTypes(__DIR__ . '/data/preg_match_php8.php');
}

require_once __DIR__ . '/data/countable.php';
yield from $this->gatherAssertTypes(__DIR__ . '/data/countable.php');

Expand Down
12 changes: 12 additions & 0 deletions tests/PHPStan/Analyser/data/preg_match_php7.php
@@ -0,0 +1,12 @@
<?php

namespace PregMatch;

use function PHPStan\Testing\assertType;

class Foo {
public function doFoo() {
assertType('0|1|false', preg_match('{}', ''));
assertType('int<0, max>|false|null', preg_match_all('{}', ''));
}
}
13 changes: 13 additions & 0 deletions tests/PHPStan/Analyser/data/preg_match_php8.php
@@ -0,0 +1,13 @@
<?php

namespace PregMatch;

use function PHPStan\Testing\assertType;

class Foo {
public function doFoo() {
assertType('0|1|false', preg_match('{}', ''));
assertType('int<0, max>|false', preg_match_all('{}', ''));

}
}

0 comments on commit 04b9c99

Please sign in to comment.