Closed elstamey closed 1 year ago
I can contribute a fix, but wanted to be sure my expectations matched the project before doing anything.
Thanks for the report @elstamey - Your problem here is that you're on Psalm 4.x.
The Psalm type InputSpecification
defined on InputFilterInterface
is an unsealed array shape (Uses ...
) - these are not supported in Psalm 4.x
Can I suggest that you baseline the issues until you've upgraded to 5.x?
As we're not going to downgrade to Psalm 4 here, I'll close this issue now.
Bug Report
Summary
We have our Classes that extend Laminas\InputFilter set up like this documentation:
Psalm shows InvalidArgument whereever we use
$this->add()
with an array of input specification in the way that is shown in documentation throughout the docs.Current behavior
Psalm error throws InvalidArgument where we use InputFilter->add because an array is no longer an expected parameter.
How to reproduce
With laminas-inputfilter installed with a minimum version of 2.16
create a class that extends InputFilter and add an input specification that is setup as an array
class ReportsSearchFilter extends InputFilter { public function init(): void { $this->add( [ 'name' => 'account_id', 'required' => false, 'validators' => [ ['name' => Digits::class,] ], ] ); } }
run psalm on the created class ReportsSearchFilter. I can confirm the invalid argument error is thrown in version 4.7, but probably before this version.
You should see an Invalid Argument error in the psalm output
Expected behavior
I expected that
$this->add([]);
would accept an array. as input since an array is used in so many documentation examples.In a commit, It looks like a new type was added to the DocBlock. At the same time InputSpecification was added as an input parament, array was removed from it.
see this commit
At first I thought that removing array was intentional, but the above referenced commit has WIP for a title, and none of the documentation indicates that array is no longer accepted input.