Skip to content

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Feb 18, 2022

if (count($functionCall->getArgs()) < 1) {
if ($argsCount < 1) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive-by cleanup

Comment on lines +9 to +23
function doFoo() {
$subject = array('1', 'a', '2', 'b', '3', 'A', 'B', '4');
$pattern = array('/\d/', '/[a-z]/', '/[1a]/');
$replace = array('A:$0', 'B:$0', 'C:$0');

assertType('array<int, string>', preg_filter($pattern, $replace, $subject));
}

function doFoo1() {
$subject = array('1', 'a', '2', 'b', '3', 'A', 'B', '4');
assertType('array<int, string>', preg_filter('/\d/', '$0', $subject));

$subject = 'hallo';
assertType('string|null', preg_filter('/\d/', '$0', $subject));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests taken from the php.net manual

@clxmstaab clxmstaab force-pushed the preg-filter branch 2 times, most recently from 98c57d7 to a4a8f93 Compare February 23, 2022 07:49
@clxmstaab clxmstaab force-pushed the preg-filter branch 2 times, most recently from 34050e9 to a03ce88 Compare February 23, 2022 12:42
@clxmstaab clxmstaab force-pushed the preg-filter branch 2 times, most recently from 8bbdee9 to 47a07b9 Compare February 28, 2022 18:22
@ondrejmirtes ondrejmirtes merged commit 12a76c8 into phpstan:master Mar 2, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the preg-filter branch March 2, 2022 09:15
@arnaud-lb
Copy link
Contributor

Thank you @staabm !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refine return type of preg_filter()
4 participants