GD can never be resource anymore since PHP 8.0

This commit is contained in:
Adrien Crivelli
2023-09-07 17:16:40 +08:00
parent 58cfc10a00
commit 18a2e65372
4 changed files with 12 additions and 28 deletions
-2
View File
@@ -19,7 +19,5 @@ parameters:
processTimeout: 300.0
checkMissingIterableValueType: false
ignoreErrors:
- '~^Parameter \#1 \$im(age)? of function (imagedestroy|imageistruecolor|imagealphablending|imagesavealpha|imagecolortransparent|imagecolorsforindex|imagesavealpha|imagesx|imagesy|imagepng|imagecolorat) expects (GdImage|resource), GdImage\|resource given\.$~'
- '~^Parameter \#2 \$src_im(age)? of function imagecopy expects (GdImage|resource), GdImage\|resource given\.$~'
# Accept a bit anything for assert methods
- '~^Parameter \#2 .* of static method PHPUnit\\Framework\\Assert\:\:assert\w+\(\) expects .*, .* given\.$~'
+1 -3
View File
@@ -159,13 +159,11 @@ class Drawing
*
* @param string $bmpFilename Path to Windows DIB (BMP) image
*
* @return GdImage|resource
*
* @deprecated 1.26 use Php function imagecreatefrombmp instead
*
* @codeCoverageIgnore
*/
public static function imagecreatefrombmp($bmpFilename)
public static function imagecreatefrombmp($bmpFilename): GdImage
{
$retVal = @imagecreatefrombmp($bmpFilename);
if ($retVal === false) {
+5 -16
View File
@@ -28,10 +28,8 @@ class MemoryDrawing extends BaseDrawing
/**
* Image resource.
*
* @var null|GdImage|resource
*/
private $imageResource;
private null|GdImage $imageResource = null;
/**
* Rendering function.
@@ -54,9 +52,6 @@ class MemoryDrawing extends BaseDrawing
*/
private $uniqueName;
/** @var null|resource */
private $alwaysNull;
/**
* Create a new MemoryDrawing.
*/
@@ -66,7 +61,6 @@ class MemoryDrawing extends BaseDrawing
$this->renderingFunction = self::RENDERING_DEFAULT;
$this->mimeType = self::MIMETYPE_DEFAULT;
$this->uniqueName = md5(mt_rand(0, 9999) . time() . mt_rand(0, 9999));
$this->alwaysNull = null;
// Initialize parent
parent::__construct();
@@ -75,9 +69,8 @@ class MemoryDrawing extends BaseDrawing
public function __destruct()
{
if ($this->imageResource) {
$rslt = @imagedestroy($this->imageResource);
// "Fix" for Scrutinizer
$this->imageResource = $rslt ? null : $this->alwaysNull;
@imagedestroy($this->imageResource);
$this->imageResource = null;
}
}
@@ -253,10 +246,8 @@ class MemoryDrawing extends BaseDrawing
/**
* Get image resource.
*
* @return null|GdImage|resource
*/
public function getImageResource()
public function getImageResource(): ?GdImage
{
return $this->imageResource;
}
@@ -264,11 +255,9 @@ class MemoryDrawing extends BaseDrawing
/**
* Set image resource.
*
* @param GdImage|resource $value
*
* @return $this
*/
public function setImageResource($value)
public function setImageResource(?GdImage $value)
{
$this->imageResource = $value;
+6 -7
View File
@@ -12,7 +12,6 @@ use PhpOffice\PhpSpreadsheet\RichText\Run;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Shared\Xls;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\Conditional;
use PhpOffice\PhpSpreadsheet\Style\Protection;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
@@ -2175,17 +2174,17 @@ class Worksheet extends BIFFwriter
*
* @param int $row The row we are going to insert the bitmap into
* @param int $col The column we are going to insert the bitmap into
* @param mixed $bitmap The bitmap filename or GD-image resource
* @param GdImage|string $bitmap The bitmap filename or GD-image resource
* @param int $x the horizontal position (offset) of the image inside the cell
* @param int $y the vertical position (offset) of the image inside the cell
* @param float $scale_x The horizontal scale
* @param float $scale_y The vertical scale
*/
public function insertBitmap($row, $col, $bitmap, $x = 0, $y = 0, $scale_x = 1, $scale_y = 1): void
public function insertBitmap($row, $col, GdImage|string $bitmap, $x = 0, $y = 0, $scale_x = 1, $scale_y = 1): void
{
$bitmap_array = (is_resource($bitmap) || $bitmap instanceof GdImage
$bitmap_array = $bitmap instanceof GdImage
? $this->processBitmapGd($bitmap)
: $this->processBitmap($bitmap));
: $this->processBitmap($bitmap);
[$width, $height, $size, $data] = $bitmap_array;
// Scale the frame of the image.
@@ -2391,11 +2390,11 @@ class Worksheet extends BIFFwriter
/**
* Convert a GD-image into the internal format.
*
* @param GdImage|resource $image The image to process
* @param GdImage $image The image to process
*
* @return array Array with data and properties of the bitmap
*/
public function processBitmapGd($image)
public function processBitmapGd(GdImage $image)
{
$width = imagesx($image);
$height = imagesy($image);