Skip to content

Support for array shape for ArrayAccess classes. #7650

@alexander-schranz

Description

@alexander-schranz

Feature request

In Symfony there is the OptionResolver component which returns a Options object which is a ArrayAccess object. This is used inside symfony forms to define form options.

As the input here is already validated I want to define the Symfony Options object like an array shape e.g.:

        return (new OptionsResolver())
            ->setDefault('account', null)
            ->setNormalizer('account', fn (Options $options, ?AccountInterface $account) => $account ?: $this->accountFactory->create([]))
            ->setDefault('visitorList', null)
            ->setNormalizer(
                'visitorList',
                function (Options $options, ?VisitorList $visitorList) {
                    /** @var Options{account: Account} $options */
                    return $visitorList ?: $this->visitorListFactory->create([
                        'account' => $options['account'],
                    ]);
                },
            );

But currently phpstan does not support this. It would be great if phpstan does support array shapes also on ArrayAccess objects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions