-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ArrayType::castToArrayKeyType() for template types
- Loading branch information
1 parent
3eb6e79
commit 0a992c2
Showing
4 changed files
with
68 additions
and
21 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
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,32 @@ | ||
<?php | ||
|
||
namespace Bug3266; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* @phpstan-template TKey | ||
* @phpstan-template TValue | ||
* @phpstan-param array<TKey, TValue> $iterator | ||
* @phpstan-return array<TKey, TValue> | ||
*/ | ||
public function iteratorToArray($iterator) | ||
{ | ||
assertType('array<TKey (method Bug3266\Foo::iteratorToArray(), argument), TValue (method Bug3266\Foo::iteratorToArray(), argument)>', $iterator); | ||
$array = []; | ||
foreach ($iterator as $key => $value) { | ||
assertType('TKey (method Bug3266\Foo::iteratorToArray(), argument)', $key); | ||
assertType('TValue (method Bug3266\Foo::iteratorToArray(), argument)', $value); | ||
$array[$key] = $value; | ||
assertType('array<TKey (method Bug3266\Foo::iteratorToArray(), argument), TValue (method Bug3266\Foo::iteratorToArray(), argument)>', $array); | ||
} | ||
|
||
assertType('array<TKey (method Bug3266\Foo::iteratorToArray(), argument), TValue (method Bug3266\Foo::iteratorToArray(), argument)>', $array); | ||
|
||
return $array; | ||
} | ||
|
||
} |