-
Notifications
You must be signed in to change notification settings - Fork 560
Fix phpstan/phpstan#6799: wrongly reported empty array #5292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
phpstan-bot
wants to merge
15
commits into
phpstan:2.1.x
from
phpstan-bot:create-pull-request/patch-39g5cp0
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
50749d7
Fix call_user_func_array not updating scope for by-reference args
VincentLanglet 2d7ce79
Use @param-out type for call_user_func_array by-reference args
phpstan-bot e30122d
Refactor call_user_func by-ref type resolution to reuse NodeScopeReso…
phpstan-bot 7e864e4
Simplify resolveCallUserFuncCalleeReflection to only support single-v…
phpstan-bot da76a4b
Add tests for union callback types in call_user_func_array by-ref han…
phpstan-bot 45fb724
Rework tests
VincentLanglet 67ba647
Address review: native return type and reorder $this check
phpstan-bot 6af1bb8
Address staabm review: native return type, early return, reorder $thi…
phpstan-bot 9ee8886
simplify
staabm 45ba2fd
Use native parameter type for resolveByRefParameterType
phpstan-bot 0487f0a
Defer resolveCallUserFuncCalleeReflection until needed, native param …
phpstan-bot 98edaa0
Add rule test for bug-6799 to verify no false positive on count() com…
phpstan-bot c295032
Replace resolveCallUserFuncCalleeReflection with CallableParametersAc…
phpstan-bot 54b6aec
Rework
VincentLanglet 3f143a8
Fix
VincentLanglet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,116 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug6799; | ||
|
|
||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| /** | ||
| * @param array<int> $items | ||
| */ | ||
| function functionProcessInts(array &$items): void | ||
| { | ||
| $items = [1, 2]; | ||
| } | ||
|
|
||
| /** | ||
| * @param array<string> $items | ||
| */ | ||
| function functionProcessStrings(array &$items): void | ||
| { | ||
| $items = ['a', 'b']; | ||
| } | ||
|
|
||
| class HelloWorld | ||
| { | ||
| /** | ||
| * @param string[] $where | ||
| * @param string $sqlTableName | ||
| * @param mixed[] $filter | ||
| * @param string $value | ||
| */ | ||
| protected function listingAddWhereFilterAtableDefault(array &$where, string $sqlTableName, array $filter, string $value): void | ||
| { | ||
| if ($value != "" && !empty($filter) && !empty($filter['sql']) && is_string($filter['sql'])) { | ||
| $where[] = "`" . $sqlTableName . "`.`" . (string)$filter['sql'] . "` = '" . $value . "'"; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param string[] $filterValues | ||
| * @param string[] $where | ||
| * @param string[] $tables | ||
| * @param mixed[] $filters | ||
| */ | ||
| protected function listingAddWhereFilterAtable(array $filterValues, array &$where, array &$tables, array $filters): void | ||
| { | ||
| if (!empty($filterValues) && !empty($filters)) { | ||
| $whereFilter = array(); | ||
| foreach ($filterValues as $type => $value) { | ||
| call_user_func_array(array($this, 'listingAddWhereFilterAtableDefault'), array(&$whereFilter, 'xxxx', $filters[$type], $value)); | ||
| } | ||
| assertType('array<string>', $whereFilter); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param array<mixed> $items | ||
| * @param-out list<int> $items | ||
| */ | ||
| protected function processWithParamOut(array &$items): void | ||
| { | ||
| $items = [1, 2, 3]; | ||
| } | ||
|
|
||
| protected function testParamOut(): void | ||
| { | ||
| $items = []; | ||
| call_user_func_array([$this, 'processWithParamOut'], [&$items]); | ||
| assertType('list<int>', $items); | ||
| } | ||
|
|
||
| /** | ||
| * @param array<int> $items | ||
| */ | ||
| protected function processInts(array &$items): void | ||
| { | ||
| $items = [1, 2]; | ||
| } | ||
|
|
||
| /** | ||
| * @param array<string> $items | ||
| */ | ||
| protected function processStrings(array &$items): void | ||
| { | ||
| $items = ['a', 'b']; | ||
| } | ||
|
|
||
| /** | ||
| * @param 'Bug6799\functionProcessInts'|'Bug6799\functionProcessStrings' $function | ||
| */ | ||
| protected function testUnionStringCallbacks(string $function): void | ||
| { | ||
| $items = []; | ||
| call_user_func_array($function, [&$items]); | ||
| assertType('array<int|string>', $items); | ||
| } | ||
|
|
||
| /** | ||
| * @param array{$this, 'processInts'}|array{$this, 'processStrings'} $callback | ||
| */ | ||
| protected function testUnionArrayCallbacks(array $callback): void | ||
| { | ||
| $items = []; | ||
| call_user_func_array($callback, [&$items]); | ||
| assertType('array<int|string>', $items); | ||
| } | ||
|
|
||
| /** | ||
| * @param 'Bug6799\functionProcessInts'|array{$this, 'processStrings'} $callback | ||
| */ | ||
| protected function testMixedUnionCallback($callback): void | ||
| { | ||
| $items = []; | ||
| call_user_func_array($callback, [&$items]); | ||
| assertType('array<int|string>', $items); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.