Options stub doesn't work as expected

Open
#322 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
php, symfony
Domain
tooling

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from phpstan/phpstan-symfony

All issues in phpstan/phpstan-symfony

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.