Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mb_str_split() / str_split() always returns non-empty-array #633

Merged
merged 6 commits into from
Aug 23, 2021

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Aug 20, 2021

@staabm staabm changed the title (mb_)?str_split() always returns non-empty-array (mb_)?str_split() always returns non-empty-array Aug 20, 2021
'$strSplitConstantStringWithInvalidSplitLengthType',
],
[
'array<int, string>&nonEmpty',
'$strSplitConstantStringWithVariableStringAndConstantSplitLength',
],
[
PHP_VERSION_ID < 80000 ? 'array<int, string>|false' : 'array<int, string>',
PHP_VERSION_ID < 80000 ? '(array<int, string>&nonEmpty)|false' : 'array<int, string>&nonEmpty',
Copy link
Contributor Author

@staabm staabm Aug 20, 2021

Choose a reason for hiding this comment

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

interessting.. sometimes a type including braces is produced, and sometimes without

Copy link
Member

Choose a reason for hiding this comment

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

$joinTypes = static function (array $types) use ($level): string {
$typeNames = [];
foreach ($types as $type) {
if ($type instanceof ClosureType || $type instanceof CallableType) {
$typeNames[] = sprintf('(%s)', $type->describe($level));
} elseif ($type instanceof IntersectionType) {
$intersectionDescription = $type->describe($level);
if (strpos($intersectionDescription, '&') !== false) {
$typeNames[] = sprintf('(%s)', $type->describe($level));
} else {
$typeNames[] = $intersectionDescription;
}
} else {
$typeNames[] = $type->describe($level);
}
}
return implode('|', $typeNames);
};

Call to function is_array() with array<int, string>&nonEmpty will always evaluate to true.
@staabm staabm changed the title (mb_)?str_split() always returns non-empty-array mb_str_split() / str_split() always returns non-empty-array Aug 23, 2021
@staabm
Copy link
Contributor Author

staabm commented Aug 23, 2021

@ondrejmirtes fixed remaining php8 error. should be good to go

@ondrejmirtes ondrejmirtes merged commit 8bf2fe0 into phpstan:master Aug 23, 2021
@ondrejmirtes
Copy link
Member

Thank you!

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