Options stub doesn't work as expected
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start with the linked PHPStan reproducer examples and compare Symfony's Options with the custom Options described in the issue. Inspect the related PHPStan issue and phpstan-symfony PR #294, then establish a minimal reproduction showing whether $options['site'] is inferred as the expected type rather than a union; done means the regression is reproducible and its expected inference is covered.
Written by the indexing model from the issue text.
Description
Related to https://github.com/phpstan/phpstan/issues/7650
and PR https://github.com/phpstan/phpstan-symfony/pull/294
cc @alexander-schranz and @ondrejmirtes
I saw the following example https://phpstan.org/r/95a7bcea-3198-4297-8770-823861adacfb
(btw now it's full of error: https://phpstan.org/r/339c6e0b-c988-4a01-b203-1047ec4f71ee)
I wrote the following code
/**
* @param Options<array{
* page: PageInterface|null,
* site: SiteInterface|null,
* choice_translation_domain: bool,
* filter_choice: array{current_page: false, request_method: string, dynamic: bool, hierarchy: string},
* }> $options
*
* @return array<PageInterface>
*/
private function getChoices(Options $options): array
{
\PHPStan\dumpType($options['site']);
And I'm getting
Dumped type: array{current_page: false, request_method: string, dynamic: bool, hierarchy:
string}|bool|Sonata\PageBundle\Model\PageInterface|Sonata\PageBundle\Model\SiteInterface|null
But I cannot reproduce the issue in the phpstan reproducer.
If you look at this PR: https://github.com/sonata-project/SonataPageBundle/pull/1654,
you'll see that
- When using the Options from Symfony, I get the wrong inference.
- When using my Options, it works fine.
Am I missing something ?
- Dominant language
- PHP
- Stars
- 800
- Forks
- 104
- Avg merge
- 4m
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from phpstan/phpstan-symfony
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
phpstan/phpstan-symfony#510 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
phpstan/phpstan-symfony#494 · 5 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
phpstan/phpstan-symfony#268 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
phpstan/phpstan-symfony#509 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
phpstan/phpstan-symfony#466 · 4 comments ·
All issues in phpstan/phpstan-symfony
Similar issues
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
phpstan/phpstan-doctrine#794 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Automattic/static-site-importer#1767 ·