PHPStan fails with Call to an undefined method STS\ZipStream\Contracts\FileContract::setFilesize()
Closed this issue · 4 comments
According to the readme, the following is possible:
$zip->add(
File::makeFromDisk(...)->setFilesize(...)
);
However, PHPStan fails with the following error: Call to an undefined method STS\ZipStream\Contracts\FileContract::setFilesize().
This is because makeFromDisk()
returns a FileContract
, and that contract doesn't have a setFileSize()
function.
It works fine in reality, since it actually returns a File
class (that implements the contract), and that class does have the setFilesize()
method.
As a workaround to get my PHPStan to pass for now, I have split the snippet up so I can manually typehint it:
/** @var File $file */
$file = File::makeFromDisk(...);
$zip->add(
$file->setFilesize(...)
);
However, it would still be nice for this to get fixed. From what I can see, makeFromDisk
can just directly use File
as its return type? Because both of the classes that it can return (S3File
and LocalFile
) both extend the File
class. I can create a PR if this is the desired solution.
Whoops I had changed the return type on make
but not makeFromDisk
. v5.0.2 tagged
Thanks a lot for the quick fix! However, 5.0.2 doesn't seem to be tagged yet haha
Ha. I tagged it locally, that's not good enough? ;-)
Pushed the tag now.