-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix return type of sprintf with single
%s
format
- Loading branch information
Showing
3 changed files
with
77 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug11201; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
/** @return array<string> */ | ||
function returnsArray(){ | ||
return []; | ||
} | ||
|
||
/** @return non-empty-string */ | ||
function returnsNonEmptyString(): string | ||
{ | ||
return 'a'; | ||
} | ||
|
||
/** @return non-falsy-string */ | ||
function returnsNonFalsyString(): string | ||
{ | ||
return '1'; | ||
} | ||
|
||
/** @return string */ | ||
function returnsJustString(): string | ||
{ | ||
return rand(0,1) === 1 ? 'foo' : ''; | ||
} | ||
|
||
$s = sprintf("%s", returnsNonEmptyString()); | ||
assertType('non-empty-string', $s); | ||
|
||
$s = sprintf("%s", returnsNonFalsyString()); | ||
assertType('non-falsy-string', $s); | ||
|
||
$s = sprintf("%s", returnsJustString()); | ||
assertType('string', $s); | ||
|
||
$s = sprintf("%s", implode(', ', array_map('intval', returnsArray()))); | ||
assertType('string', $s); | ||
|
||
$s = sprintf('%2$s', 1234, returnsNonFalsyString()); | ||
assertType('non-falsy-string', $s); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters