-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8567 from nosnickid/fix-min-max-return-type
Fix MinMaxReturnTypeProvider when handling TDependentListKeys
- Loading branch information
Showing
2 changed files
with
58 additions
and
5 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,53 @@ | ||
<?php | ||
|
||
namespace Psalm\Tests\ReturnTypeProvider; | ||
|
||
use Psalm\Tests\TestCase; | ||
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait; | ||
|
||
class MinMaxReturnTypeProviderTest extends TestCase | ||
{ | ||
use ValidCodeAnalysisTestTrait; | ||
|
||
public function providerValidCodeParse(): iterable | ||
{ | ||
yield 'literalInt' => [ | ||
'<?php | ||
$min = min(1, 2); | ||
$max = max(3, 4); | ||
', | ||
[ | ||
'$min' => 'int', | ||
'$max' => 'int', | ||
], | ||
]; | ||
yield 'nonInt' => [ | ||
'<?php | ||
$min = min("a", "b"); | ||
$max = max("x", "y"); | ||
', | ||
[ | ||
'$min' => 'string', | ||
'$max' => 'string', | ||
], | ||
]; | ||
yield 'maxIntRange' => [ | ||
'<?php | ||
$headers = fgetcsv(fopen("test.txt", "r")); | ||
$h0 = $h1 = null; | ||
foreach($headers as $i => $v) { | ||
if ($v === "") $h0 = $i; | ||
if ($v === "") $h1 = $i; | ||
} | ||
if ($h0 === null || $h1 === null) throw new \Exception(); | ||
$min = min($h0, $h1); | ||
$max = max($h0, $h1); | ||
', | ||
[ | ||
'$min' => 'int<0, max>', | ||
'$max' => 'int<0, max>', | ||
], | ||
]; | ||
} | ||
} |