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
non-empty-string
false positive detection
#10897
Labels
Comments
I found these snippets: https://psalm.dev/r/cd3d4258fb<?php
/**
* @return non-empty-string
*/
function foo(string $i): string {
$i = trim($i);
$l = strlen($i);
if (0 === $l) {
throw new \InvalidArgumentException('The alphabet has to be a non-empty string.');
}
return $i;
}
/**
* @return non-empty-string
*/
function bar(string $i): string {
$i = trim($i);
if (0 === strlen($i)) {
throw new \InvalidArgumentException('The alphabet has to be a non-empty string.');
}
return $i;
}
/**
* @return non-empty-string
*/
function baz(string $i): string {
$i = trim($i);
// strange, because '0' will be empty for `empty` function
if (empty($i)) {
throw new \InvalidArgumentException('The alphabet has to be a non-empty string.');
}
return $i;
}
|
The strlen thing is a duplicate of #7387
Please elaborate, I don't see any strange behavior there. |
When I wrote this, it was a bug with an |
I found these snippets: https://psalm.dev/r/f6cae1f221<?php
/**
* @return non-empty-string
*/
function baz(string $s): string {
$s = trim($s);
if (empty($s)) {
throw new \InvalidArgumentException('String is empty');
}
return $s;
}
baz('');
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a false positive detection for the
non-empty-string
type and strange behavior with theempty
function.https://psalm.dev/r/cd3d4258fb
The text was updated successfully, but these errors were encountered: