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 committed Feb 18, 2022
1 parent f255672 commit 7c59c40
Show file tree
Hide file tree
Showing 4 changed files with 33 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
7 changes: 7 additions & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Expand Up @@ -706,6 +706,13 @@ public function dataFileAsserts(): iterable

yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6488.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6624.php');

if (PHP_VERSION_ID < 80000) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/preg_match_php7.php');
}
if (PHP_VERSION_ID >= 80000) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/preg_match_php8.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 7c59c40

Please sign in to comment.