Skip to content

PHPStan fails when a choice field is the last field in a repeater and other fields are added after repeater #349

@thunderdw

Description

@thunderdw

If a choice field (Radio, Select, etc.) is the last field in a repeater, any field after the endRepeater() call will cause PHPStan to throw the following error:

Call to method addRadio() on an unknown class Log1x\AcfComposer\Builder\Builder.
🪪  class.notFound

For example, this causes the above error:

$fields
    ->addRepeater('repeater')
        ->addImage('image')
        ->addSelect('select', [
            'choices' => [
                1,
                2,
            ]
        ])
    ->endRepeater()
    ->addText('text');

But this does not:

$fields
    ->addRepeater('repeater')
        ->addSelect('select', [
            'choices' => [
                1,
                2,
            ]
        ])
        ->addImage('image')
    ->endRepeater()
    ->addText('text');

This can be fixed by adding use Log1x\AcfComposer\Builder; to src/Builder/ChoiceFieldBuilder.php - this is already on the similar src/Builder/FieldBuilder.php class.

I'll be making a PR shortlly to add the use statement

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions