-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support ARRAY_FILTER_USE_KEY and ARRAY_FILTER_USE_BOTH
- Loading branch information
1 parent
9b0ff1d
commit 138cabd
Showing
3 changed files
with
76 additions
and
3 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,48 @@ | ||
<?php | ||
|
||
namespace Bug3132; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
use const ARRAY_FILTER_USE_BOTH; | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* @param array<string,object> $objects | ||
* | ||
* @return array<string,object> | ||
*/ | ||
function filter(array $objects) : array | ||
{ | ||
return array_filter($objects, static function ($key) { | ||
assertType('string', $key); | ||
}, ARRAY_FILTER_USE_KEY); | ||
} | ||
|
||
/** | ||
* @param array<string,object> $objects | ||
* | ||
* @return array<string,object> | ||
*/ | ||
function bar(array $objects) : array | ||
{ | ||
return array_filter($objects, static function ($val) { | ||
assertType('object', $val); | ||
}); | ||
} | ||
|
||
/** | ||
* @param array<string,object> $objects | ||
* | ||
* @return array<string,object> | ||
*/ | ||
function baz(array $objects) : array | ||
{ | ||
return array_filter($objects, static function ($val, $key) { | ||
assertType('string', $key); | ||
assertType('object', $val); | ||
}, ARRAY_FILTER_USE_BOTH); | ||
} | ||
|
||
} |