Phpstan Differences from Php7 to Php8 (#2631)

These changes were already implemented as PR #2428. They were, alas, regressed by PR #2585. If at first you don't succeed ...

As configured, Phpstan running under Php7 reports no errors. However, running under Php8, it reports 100 (!) errors. The vast majority of these are due to two reasons:
- renaming parameters in Php builtin functions in preparation for named parameters.
- using the new class GdImage rather than type resource as the argument type for many image-based functions.

Regardless of the cause, this will be a problem sooner or later. This PR is an attempt to get ahead of that problem. For source members, it tweaks only the Phpstan configuration files, without changing any PhpSpreadsheet code. For the small number of test members involved, the code is fixed. Php7 and Php8 both report no errors with this configuration.

Because this involves no changes to code, and because Phpstan baseline is a common cause of merge difficulties, I will probably merge this in a day or two, more quickly than I customarily do.
This commit is contained in:
oleibman 2022-03-01 01:53:12 -08:00 committed by GitHub
parent fe969f59cc
commit 8258919d72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 110 additions and 146 deletions

View File

@ -146,12 +146,12 @@ parameters:
path: src/PhpSpreadsheet/Calculation/Calculation.php
-
message: "#^Parameter \\#1 \\$str of function trim expects string, int\\|string given\\.$#"
message: "#^Parameter \\#1 \\$str(ing)? of function trim expects string, int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php
-
message: "#^Parameter \\#1 \\$str of function trim expects string, null given\\.$#"
message: "#^Parameter \\#1 \\$str(ing)? of function trim expects string, null given\\.$#"
count: 2
path: src/PhpSpreadsheet/Calculation/Calculation.php
@ -361,12 +361,12 @@ parameters:
path: src/PhpSpreadsheet/Calculation/Engineering/BitWise.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\<0, 281474976710655\\>\\|string given\\.$#"
message: "#^Parameter \\#1 \\$num(ber)? of function floor expects float(.int)?, float\\|int\\<0, 281474976710655\\>\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Engineering/BitWise.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
message: "#^Parameter \\#1 \\$num(ber)? of function floor expects float(.int)?, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Engineering/BitWise.php
@ -821,12 +821,12 @@ parameters:
path: src/PhpSpreadsheet/Calculation/LookupRef/RowColumnInformation.php
-
message: "#^Parameter \\#1 \\$low of function range expects float\\|int\\|string, string\\|null given\\.$#"
message: "#^Parameter \\#1 \\$(low|start) of function range expects float\\|int\\|string, string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/RowColumnInformation.php
-
message: "#^Parameter \\#2 \\$high of function range expects float\\|int\\|string, string\\|null given\\.$#"
message: "#^Parameter \\#2 \\$(high|end) of function range expects float\\|int\\|string, string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/RowColumnInformation.php
@ -1256,12 +1256,12 @@ parameters:
path: src/PhpSpreadsheet/Cell/Coordinate.php
-
message: "#^Parameter \\#1 \\$input of function array_chunk expects array, array\\<int, string\\>\\|false given\\.$#"
message: "#^Parameter \\#1 \\$(input|array) of function array_chunk expects array, array\\<int, string\\>\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Cell/Coordinate.php
-
message: "#^Parameter \\#2 \\$str of function explode expects string, array\\<int, string\\>\\|string given\\.$#"
message: "#^Parameter \\#2 \\$str(ing)? of function explode expects string, array\\<int, string\\>\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Cell/Coordinate.php
@ -1946,7 +1946,7 @@ parameters:
path: src/PhpSpreadsheet/Helper/Html.php
-
message: "#^Parameter \\#1 \\$function of function call_user_func expects callable\\(\\)\\: mixed, array\\{\\$this\\(PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\), mixed\\} given\\.$#"
message: "#^Parameter \\#1 \\$(function|callback) of function call_user_func expects callable\\(\\)\\: mixed, array\\{\\$this\\(PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\), mixed\\} given\\.$#"
count: 1
path: src/PhpSpreadsheet/Helper/Html.php
@ -2521,7 +2521,7 @@ parameters:
path: src/PhpSpreadsheet/Reader/Xls/MD5.php
-
message: "#^Parameter \\#1 \\$input of function array_values expects array, array\\|false given\\.$#"
message: "#^Parameter \\#1 \\$(input|array) of function array_values expects array, array\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Xls/MD5.php
@ -3336,37 +3336,37 @@ parameters:
path: src/PhpSpreadsheet/Shared/Drawing.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Drawing\\:\\:imagecreatefrombmp\\(\\) should return GdImage\\|resource but returns resource\\|false\\.$#"
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Drawing\\:\\:imagecreatefrombmp\\(\\) should return GdImage\\|resource but returns (GdImage|resource)\\|false\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/Drawing.php
-
message: "#^Parameter \\#1 \\$fp of function feof expects resource, resource\\|false given\\.$#"
message: "#^Parameter \\#1 \\$(fp|stream) of function feof expects resource, resource\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/Drawing.php
-
message: "#^Parameter \\#1 \\$fp of function fread expects resource, resource\\|false given\\.$#"
message: "#^Parameter \\#1 \\$(fp|stream) of function fread expects resource, resource\\|false given\\.$#"
count: 2
path: src/PhpSpreadsheet/Shared/Drawing.php
-
message: "#^Parameter \\#1 \\$im of function imagecolorallocate expects resource, resource\\|false given\\.$#"
message: "#^Parameter \\#1 \\$im(age)? of function imagecolorallocate expects (GdImage|resource), (GdImage|resource)\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/Drawing.php
-
message: "#^Parameter \\#1 \\$im of function imagesetpixel expects resource, resource\\|false given\\.$#"
message: "#^Parameter \\#1 \\$im(age)? of function imagesetpixel expects (GdImage|resource), (GdImage|resource)\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/Drawing.php
-
message: "#^Parameter \\#1 \\$x_size of function imagecreatetruecolor expects int, float\\|int given\\.$#"
message: "#^Parameter \\#1 \\$(x_size|width) of function imagecreatetruecolor expects int, float\\|int given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/Drawing.php
-
message: "#^Parameter \\#2 \\$data of function unpack expects string, string\\|false given\\.$#"
message: "#^Parameter \\#2 \\$(data|string) of function unpack expects string, string\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/Drawing.php
@ -3376,7 +3376,7 @@ parameters:
path: src/PhpSpreadsheet/Shared/Drawing.php
-
message: "#^Parameter \\#2 \\$y_size of function imagecreatetruecolor expects int, float\\|int given\\.$#"
message: "#^Parameter \\#2 \\$(y_size|height) of function imagecreatetruecolor expects int, float\\|int given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/Drawing.php
@ -3396,7 +3396,7 @@ parameters:
path: src/PhpSpreadsheet/Shared/Drawing.php
-
message: "#^Parameter \\#4 \\$col of function imagesetpixel expects int, int\\|false given\\.$#"
message: "#^Parameter \\#4 \\$col(or)? of function imagesetpixel expects int, int\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/Drawing.php
@ -3596,7 +3596,7 @@ parameters:
path: src/PhpSpreadsheet/Shared/JAMA/Matrix.php
-
message: "#^Parameter \\#1 \\$str of function trim expects string, float\\|int given\\.$#"
message: "#^Parameter \\#1 \\$str(ing)? of function trim expects string, float\\|int given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/JAMA/Matrix.php
@ -3676,7 +3676,7 @@ parameters:
path: src/PhpSpreadsheet/Shared/OLE.php
-
message: "#^Parameter \\#2 \\$data of function unpack expects string, string\\|false given\\.$#"
message: "#^Parameter \\#2 \\$(data|string) of function unpack expects string, string\\|false given\\.$#"
count: 3
path: src/PhpSpreadsheet/Shared/OLE.php
@ -3716,7 +3716,7 @@ parameters:
path: src/PhpSpreadsheet/Shared/OLE.php
-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, string given\\.$#"
message: "#^Parameter \\#1 \\$(var|value) of function count expects array\\|Countable, string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
@ -4061,7 +4061,7 @@ parameters:
path: src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php
-
message: "#^Parameter \\#2 \\.\\.\\.\\$args of function array_merge expects array, float given\\.$#"
message: "#^Parameter \\#2 \\.\\.\\.\\$(args|arrays) of function array_merge expects array, float given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php
@ -4361,7 +4361,7 @@ parameters:
path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php
-
message: "#^Parameter \\#2 \\$str of function explode expects string, string\\|null given\\.$#"
message: "#^Parameter \\#2 \\$str(ing)? of function explode expects string, string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php
@ -4486,7 +4486,7 @@ parameters:
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
-
message: "#^Parameter \\#2 \\$str of function explode expects string, string\\|null given\\.$#"
message: "#^Parameter \\#2 \\$str(ing)? of function explode expects string, string\\|null given\\.$#"
count: 5
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
@ -4581,7 +4581,7 @@ parameters:
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
-
message: "#^Parameter \\#1 \\$input of function array_splice expects array, ArrayObject\\<int, PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\> given\\.$#"
message: "#^Parameter \\#1 \\$(input|array) of function array_splice expects array, ArrayObject\\<int, PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\> given\\.$#"
count: 1
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
@ -4606,7 +4606,7 @@ parameters:
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
-
message: "#^Parameter \\#2 \\$start of function substr expects int, int\\<0, max\\>\\|false given\\.$#"
message: "#^Parameter \\#2 \\$(start|offset) of function substr expects int, int(\\<0, max\\>)?\\|false given\\.$#"
count: 2
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
@ -4931,12 +4931,12 @@ parameters:
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Parameter \\#1 \\$im of function imagepng expects resource, GdImage\\|resource given\\.$#"
message: "#^Parameter \\#1 \\$im(age)? of function imagepng expects (GdImage|resource), GdImage\\|resource given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Parameter \\#1 \\$str of function base64_encode expects string, string\\|false given\\.$#"
message: "#^Parameter \\#1 \\$str(ing)? of function base64_encode expects string, string\\|false given\\.$#"
count: 2
path: src/PhpSpreadsheet/Writer/Html.php
@ -5066,12 +5066,12 @@ parameters:
path: src/PhpSpreadsheet/Writer/Xls.php
-
message: "#^Parameter \\#1 \\$im of function imagepng expects resource, GdImage\\|resource given\\.$#"
message: "#^Parameter \\#1 \\$im(age)? of function imagepng expects (GdImage|resource), GdImage\\|resource given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Xls.php
-
message: "#^Parameter \\#1 \\$im of function imagepng expects resource, resource\\|false given\\.$#"
message: "#^Parameter \\#1 \\$im(age)? of function imagepng expects (GdImage|resource), (GdImage|resource)\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Xls.php
@ -5256,7 +5256,7 @@ parameters:
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
-
message: "#^Parameter \\#1 \\$im of function imagecolorat expects resource, GdImage\\|resource given\\.$#"
message: "#^Parameter \\#1 \\$im(age)? of function imagecolorat expects (GdImage|resource), GdImage\\|resource given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
@ -5271,12 +5271,12 @@ parameters:
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
-
message: "#^Parameter \\#2 \\$col of function imagecolorsforindex expects int, int\\|false given\\.$#"
message: "#^Parameter \\#2 \\$col(or)? of function imagecolorsforindex expects int, int\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
-
message: "#^Parameter \\#2 \\$data of function unpack expects string, string\\|false given\\.$#"
message: "#^Parameter \\#2 \\$(data|string) of function unpack expects string, string\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
@ -5286,7 +5286,7 @@ parameters:
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
-
message: "#^Parameter \\#2 \\$pieces of function implode expects array, array\\<int, string\\>\\|false given\\.$#"
message: "#^Parameter \\#2 \\$(pieces|array) of function implode expects array(\\|null)?, array\\<int, string\\>\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
@ -5371,7 +5371,7 @@ parameters:
path: src/PhpSpreadsheet/Writer/Xlsx.php
-
message: "#^Parameter \\#1 \\$function of function call_user_func expects callable\\(\\)\\: mixed, string given\\.$#"
message: "#^Parameter \\#1 \\$(function|callback) of function call_user_func expects callable\\(\\)\\: mixed, string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Xlsx.php
@ -5850,51 +5850,11 @@ parameters:
count: 2
path: tests/PhpSpreadsheetTests/Functional/ConditionalStopIfTrueTest.php
-
message: "#^Cannot call method getUrl\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Hyperlink\\|null\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Functional/DrawingImageHyperlinkTest.php
-
message: "#^Parameter \\#1 \\$im of function imagecolorallocate expects resource, resource\\|false given\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Functional/DrawingImageHyperlinkTest.php
-
message: "#^Parameter \\#1 \\$im of function imagestring expects resource, resource\\|false given\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Functional/DrawingImageHyperlinkTest.php
-
message: "#^Parameter \\#1 \\$value of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\MemoryDrawing\\:\\:setImageResource\\(\\) expects GdImage\\|resource, resource\\|false given\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Functional/DrawingImageHyperlinkTest.php
-
message: "#^Parameter \\#6 \\$col of function imagestring expects int, int\\|false given\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Functional/DrawingImageHyperlinkTest.php
-
message: "#^Cannot call method getPageSetup\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
count: 5
path: tests/PhpSpreadsheetTests/Functional/PrintAreaTest.php
-
message: "#^Cannot access offset 'size' on array\\{0\\: int, 1\\: int, 2\\: int, 3\\: int, 4\\: int, 5\\: int, 6\\: int, 7\\: int, \\.\\.\\.\\}\\|false\\.$#"
count: 2
path: tests/PhpSpreadsheetTests/Functional/StreamTest.php
-
message: "#^Parameter \\#1 \\$filename of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\IWriter\\:\\:save\\(\\) expects resource\\|string, resource\\|false given\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Functional/StreamTest.php
-
message: "#^Parameter \\#1 \\$fp of function fstat expects resource, resource\\|false given\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Functional/StreamTest.php
-
message: "#^Parameter \\#1 \\$expected of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) expects class\\-string\\<object\\>, string given\\.$#"
count: 3
@ -6050,26 +6010,6 @@ parameters:
count: 1
path: tests/PhpSpreadsheetTests/Worksheet/AutoFilter/ColumnTest.php
-
message: "#^Parameter \\#1 \\$im of function imagecolorallocate expects resource, resource\\|false given\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Worksheet/DrawingTest.php
-
message: "#^Parameter \\#1 \\$im of function imagestring expects resource, resource\\|false given\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Worksheet/DrawingTest.php
-
message: "#^Parameter \\#1 \\$value of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\MemoryDrawing\\:\\:setImageResource\\(\\) expects GdImage\\|resource, resource\\|false given\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Worksheet/DrawingTest.php
-
message: "#^Parameter \\#6 \\$col of function imagestring expects int, int\\|false given\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Worksheet/DrawingTest.php
-
message: "#^Parameter \\#2 \\$rowIndex of class PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowCellIterator constructor expects int, string given\\.$#"
count: 1

View File

@ -10,33 +10,43 @@ class DrawingImageHyperlinkTest extends AbstractFunctional
{
public function testDrawingImageHyperlinkTest(): void
{
$baseUrl = 'https://github.com/PHPOffice/PhpSpreadsheet';
$spreadsheet = new Spreadsheet();
$aSheet = $spreadsheet->getActiveSheet();
$gdImage = @imagecreatetruecolor(120, 20);
$textColor = imagecolorallocate($gdImage, 255, 255, 255);
imagestring($gdImage, 1, 5, 5, 'Created with PhpSpreadsheet', $textColor);
$textColor = ($gdImage === false) ? false : imagecolorallocate($gdImage, 255, 255, 255);
if ($gdImage === false || $textColor === false) {
self::fail('imagecreatetruecolor or imagecolorallocate failed');
} else {
$baseUrl = 'https://github.com/PHPOffice/PhpSpreadsheet';
$spreadsheet = new Spreadsheet();
$drawing = new MemoryDrawing();
$drawing->setName('In-Memory image 1');
$drawing->setDescription('In-Memory image 1');
$drawing->setCoordinates('A1');
$drawing->setImageResource($gdImage);
$drawing->setRenderingFunction(
MemoryDrawing::RENDERING_JPEG
);
$drawing->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT);
$drawing->setHeight(36);
$hyperLink = new Hyperlink($baseUrl, 'test image');
$drawing->setHyperlink($hyperLink);
$drawing->setWorksheet($aSheet);
$aSheet = $spreadsheet->getActiveSheet();
imagestring($gdImage, 1, 5, 5, 'Created with PhpSpreadsheet', $textColor);
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
$drawing = new MemoryDrawing();
$drawing->setName('In-Memory image 1');
$drawing->setDescription('In-Memory image 1');
$drawing->setCoordinates('A1');
$drawing->setImageResource($gdImage);
$drawing->setRenderingFunction(
MemoryDrawing::RENDERING_JPEG
);
$drawing->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT);
$drawing->setHeight(36);
$hyperLink = new Hyperlink($baseUrl, 'test image');
$drawing->setHyperlink($hyperLink);
$drawing->setWorksheet($aSheet);
foreach ($reloadedSpreadsheet->getActiveSheet()->getDrawingCollection() as $pDrawing) {
self::assertEquals('https://github.com/PHPOffice/PhpSpreadsheet', $pDrawing->getHyperlink()->getUrl(), 'functional test drawing hyperlink');
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
$spreadsheet->disconnectWorksheets();
foreach ($reloadedSpreadsheet->getActiveSheet()->getDrawingCollection() as $pDrawing) {
$getHyperlink = $pDrawing->getHyperlink();
if ($getHyperlink === null) {
self::fail('getHyperlink returned null');
} else {
self::assertEquals('https://github.com/PHPOffice/PhpSpreadsheet', $getHyperlink->getUrl(), 'functional test drawing hyperlink');
}
}
$reloadedSpreadsheet->disconnectWorksheets();
}
}
}

View File

@ -39,12 +39,22 @@ class StreamTest extends TestCase
$writer = IOFactory::createWriter($spreadsheet, $format);
$stream = fopen('php://memory', 'wb+');
self::assertSame(0, fstat($stream)['size']);
$stat = ($stream === false) ? false : fstat($stream);
if ($stream === false || $stat === false) {
self::fail('fopen or fstat failed');
} else {
self::assertSame(0, $stat['size']);
$writer->save($stream);
$writer->save($stream);
self::assertIsResource($stream, 'should not close the stream for further usage out of PhpSpreadsheet');
self::assertGreaterThan(0, fstat($stream)['size'], 'something should have been written to the stream');
self::assertGreaterThan(0, ftell($stream), 'should not be rewinded, because not all streams support it');
self::assertIsResource($stream, 'should not close the stream for further usage out of PhpSpreadsheet');
$stat = fstat($stream);
if ($stat === false) {
self::fail('fstat failed');
} else {
self::assertGreaterThan(0, $stat['size'], 'something should have been written to the stream');
}
self::assertGreaterThan(0, ftell($stream), 'should not be rewinded, because not all streams support it');
}
}
}

View File

@ -10,31 +10,35 @@ class DrawingTest extends TestCase
{
public function testCloningWorksheetWithImages(): void
{
$spreadsheet = new Spreadsheet();
$aSheet = $spreadsheet->getActiveSheet();
$gdImage = @imagecreatetruecolor(120, 20);
$textColor = imagecolorallocate($gdImage, 255, 255, 255);
imagestring($gdImage, 1, 5, 5, 'Created with PhpSpreadsheet', $textColor);
$textColor = ($gdImage === false) ? false : imagecolorallocate($gdImage, 255, 255, 255);
if ($gdImage === false || $textColor === false) {
self::fail('imagecreatetruecolor or imagecolorallocate failed');
} else {
$spreadsheet = new Spreadsheet();
$aSheet = $spreadsheet->getActiveSheet();
imagestring($gdImage, 1, 5, 5, 'Created with PhpSpreadsheet', $textColor);
$drawing = new MemoryDrawing();
$drawing->setName('In-Memory image 1');
$drawing->setDescription('In-Memory image 1');
$drawing->setCoordinates('A1');
$drawing->setImageResource($gdImage);
$drawing->setRenderingFunction(
MemoryDrawing::RENDERING_JPEG
);
$drawing->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT);
$drawing->setHeight(36);
$drawing->setWorksheet($aSheet);
$drawing = new MemoryDrawing();
$drawing->setName('In-Memory image 1');
$drawing->setDescription('In-Memory image 1');
$drawing->setCoordinates('A1');
$drawing->setImageResource($gdImage);
$drawing->setRenderingFunction(
MemoryDrawing::RENDERING_JPEG
);
$drawing->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT);
$drawing->setHeight(36);
$drawing->setWorksheet($aSheet);
$originDrawingCount = count($aSheet->getDrawingCollection());
$clonedWorksheet = clone $aSheet;
$clonedDrawingCount = count($clonedWorksheet->getDrawingCollection());
$originDrawingCount = count($aSheet->getDrawingCollection());
$clonedWorksheet = clone $aSheet;
$clonedDrawingCount = count($clonedWorksheet->getDrawingCollection());
self::assertEquals($originDrawingCount, $clonedDrawingCount);
self::assertNotSame($aSheet, $clonedWorksheet);
self::assertNotSame($aSheet->getDrawingCollection(), $clonedWorksheet->getDrawingCollection());
self::assertEquals($originDrawingCount, $clonedDrawingCount);
self::assertNotSame($aSheet, $clonedWorksheet);
self::assertNotSame($aSheet->getDrawingCollection(), $clonedWorksheet->getDrawingCollection());
$spreadsheet->disconnectWorksheets();
}
}
}