-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10a2b24
commit 330eb22
Showing
3 changed files
with
72 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Bug4545; | ||
|
||
use Closure; | ||
use Ds\Hashable; | ||
use Ds\Map; | ||
use Ds\Set; | ||
use function PHPStan\Analyser\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* Returns keys which either exist only in one of the maps or exist in both but their associated values are not equal. | ||
* | ||
* @template TKey of Hashable | ||
* @template TValue1 | ||
* @template TValue2 | ||
* | ||
* @param Map<TKey, TValue1> $firstMap | ||
* @param Map<TKey, TValue2> $secondMap | ||
* @param Closure(TValue1, TValue2): bool $comparator | ||
* | ||
* @return Set<TKey> | ||
*/ | ||
function compareMaps(Map $firstMap, Map $secondMap, Closure $comparator): Set | ||
{ | ||
$firstMapKeys = $firstMap->keys(); | ||
$secondMapKeys = $secondMap->keys(); | ||
$keys = $firstMapKeys->xor($secondMapKeys); | ||
$intersect = $firstMapKeys->intersect($secondMapKeys); | ||
foreach ($intersect as $key) { | ||
assertType('TValue1 (method Bug4545\Foo::compareMaps(), argument)', $firstMap->get($key)); | ||
assertType('TValue2 (method Bug4545\Foo::compareMaps(), argument)', $secondMap->get($key)); | ||
assertType('int|TValue2 (method Bug4545\Foo::compareMaps(), argument)', $secondMap->get($key, 1)); | ||
} | ||
|
||
return $keys; | ||
} | ||
|
||
} | ||
|