Skip to content

non-falsy-string cannot be false #3972

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Type/Accessory/AccessoryNonFalsyStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ public function toInteger(): Type
return TypeCombinator::remove(new IntegerType(), new ConstantIntegerType(0));
}

public function toBoolean(): BooleanType
{
return new ConstantBooleanType(true);
}

public function toFloat(): Type
{
return new FloatType();
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/nsrt/non-falsy-string.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Foo {
*/
public function bar($nonFalseyString, $truthyString) {
assertType('int<min, -1>|int<1, max>', (int) $nonFalseyString);
assertType('true', (bool) $nonFalseyString);
// truthy-string is an alias for non-falsy-string
assertType('non-falsy-string', $truthyString);
}
Expand Down
Loading