I'm working on a Laravel project and there happens to be a code snippet like this:
sprintf("%s %s", __('foo.bar.buzz'), __('foo.bar.baz'));
Note that the __ function is a helper function from Laravel. The PHPDoc comment for the __ function includes the line @return string|array|null.
This trigger a phpstan error since sprintf cannot take an array as one of its optional parameters.
:49 Parameter #2 ...$values of function sprintf expects bool|float|int|string|null, array|string|null given.
:49 Parameter #3 ...$values of function sprintf expects bool|float|int|string|null, array|string|null given.
I added phpstan-ignore lines on the problematic code so it becomes
sprintf("%s %s",
__('foo.bar.buzz'), /* @phpstan-ignore argument.type */
__('foo.bar.baz') /* @phpstan-ignore argument.type */
);
and the error went away on my local.
However, when I push the changes to a remote GitLab repo, the errors still occured on the GitLab CI. I can make sure each __ function calls never returns an array.
Is there a workaround for this issue?