safe
safe copied to clipboard
GD extension - resource is replaced by GdImage in PHP8
In a lot of GD extension functions, the previously passed resource has been replaced by GdImage in PHP8. Our docblocks are incorrect. (see: https://github.com/thecodingmachine/safe/blob/master/generated/image.php)
This is really annoying, especially if you use static analysis.
yes, hitting this issue. Any sensible workarounds?
I'm using safe + rector + phpstan, and PHPstan aint happy at all
For reference, my current approach is to use some type forcing comments, eg
/** @var GdImage $image */
$image = match ($this->sourceImageExtension) {
self::EXT_WEBP => \Safe\imagecreatefromwebp($this->sourceImageUrl),
self::EXT_PNG => \Safe\imagecreatefrompng($this->sourceImageUrl),
self::EXT_JPG => \Safe\imagecreatefromjpeg($this->sourceImageUrl),
default => throw new RuntimeException(
'Unexpected source image extension "' . $this->sourceImageExtension . '"'
)
};
and then a liberal sprinkling of
/** @phpstan-ignore-next-line wrong docblocks in safe */
it's ugly but works for now