Skip to content

Commit 8258919

Browse files
authored
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.
1 parent fe969f5 commit 8258919

File tree

4 files changed

+115
-151
lines changed

4 files changed

+115
-151
lines changed

phpstan-baseline.neon

Lines changed: 36 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ parameters:
146146
path: src/PhpSpreadsheet/Calculation/Calculation.php
147147

148148
-
149-
message: "#^Parameter \\#1 \\$str of function trim expects string, int\\|string given\\.$#"
149+
message: "#^Parameter \\#1 \\$str(ing)? of function trim expects string, int\\|string given\\.$#"
150150
count: 1
151151
path: src/PhpSpreadsheet/Calculation/Calculation.php
152152

153153
-
154-
message: "#^Parameter \\#1 \\$str of function trim expects string, null given\\.$#"
154+
message: "#^Parameter \\#1 \\$str(ing)? of function trim expects string, null given\\.$#"
155155
count: 2
156156
path: src/PhpSpreadsheet/Calculation/Calculation.php
157157

@@ -361,12 +361,12 @@ parameters:
361361
path: src/PhpSpreadsheet/Calculation/Engineering/BitWise.php
362362

363363
-
364-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\<0, 281474976710655\\>\\|string given\\.$#"
364+
message: "#^Parameter \\#1 \\$num(ber)? of function floor expects float(.int)?, float\\|int\\<0, 281474976710655\\>\\|string given\\.$#"
365365
count: 1
366366
path: src/PhpSpreadsheet/Calculation/Engineering/BitWise.php
367367

368368
-
369-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
369+
message: "#^Parameter \\#1 \\$num(ber)? of function floor expects float(.int)?, float\\|int\\|string given\\.$#"
370370
count: 1
371371
path: src/PhpSpreadsheet/Calculation/Engineering/BitWise.php
372372

@@ -821,12 +821,12 @@ parameters:
821821
path: src/PhpSpreadsheet/Calculation/LookupRef/RowColumnInformation.php
822822

823823
-
824-
message: "#^Parameter \\#1 \\$low of function range expects float\\|int\\|string, string\\|null given\\.$#"
824+
message: "#^Parameter \\#1 \\$(low|start) of function range expects float\\|int\\|string, string\\|null given\\.$#"
825825
count: 1
826826
path: src/PhpSpreadsheet/Calculation/LookupRef/RowColumnInformation.php
827827

828828
-
829-
message: "#^Parameter \\#2 \\$high of function range expects float\\|int\\|string, string\\|null given\\.$#"
829+
message: "#^Parameter \\#2 \\$(high|end) of function range expects float\\|int\\|string, string\\|null given\\.$#"
830830
count: 1
831831
path: src/PhpSpreadsheet/Calculation/LookupRef/RowColumnInformation.php
832832

@@ -1256,12 +1256,12 @@ parameters:
12561256
path: src/PhpSpreadsheet/Cell/Coordinate.php
12571257

12581258
-
1259-
message: "#^Parameter \\#1 \\$input of function array_chunk expects array, array\\<int, string\\>\\|false given\\.$#"
1259+
message: "#^Parameter \\#1 \\$(input|array) of function array_chunk expects array, array\\<int, string\\>\\|false given\\.$#"
12601260
count: 1
12611261
path: src/PhpSpreadsheet/Cell/Coordinate.php
12621262

12631263
-
1264-
message: "#^Parameter \\#2 \\$str of function explode expects string, array\\<int, string\\>\\|string given\\.$#"
1264+
message: "#^Parameter \\#2 \\$str(ing)? of function explode expects string, array\\<int, string\\>\\|string given\\.$#"
12651265
count: 1
12661266
path: src/PhpSpreadsheet/Cell/Coordinate.php
12671267

@@ -1946,7 +1946,7 @@ parameters:
19461946
path: src/PhpSpreadsheet/Helper/Html.php
19471947

19481948
-
1949-
message: "#^Parameter \\#1 \\$function of function call_user_func expects callable\\(\\)\\: mixed, array\\{\\$this\\(PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\), mixed\\} given\\.$#"
1949+
message: "#^Parameter \\#1 \\$(function|callback) of function call_user_func expects callable\\(\\)\\: mixed, array\\{\\$this\\(PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\), mixed\\} given\\.$#"
19501950
count: 1
19511951
path: src/PhpSpreadsheet/Helper/Html.php
19521952

@@ -2521,7 +2521,7 @@ parameters:
25212521
path: src/PhpSpreadsheet/Reader/Xls/MD5.php
25222522

25232523
-
2524-
message: "#^Parameter \\#1 \\$input of function array_values expects array, array\\|false given\\.$#"
2524+
message: "#^Parameter \\#1 \\$(input|array) of function array_values expects array, array\\|false given\\.$#"
25252525
count: 1
25262526
path: src/PhpSpreadsheet/Reader/Xls/MD5.php
25272527

@@ -3336,37 +3336,37 @@ parameters:
33363336
path: src/PhpSpreadsheet/Shared/Drawing.php
33373337

33383338
-
3339-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Drawing\\:\\:imagecreatefrombmp\\(\\) should return GdImage\\|resource but returns resource\\|false\\.$#"
3339+
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Drawing\\:\\:imagecreatefrombmp\\(\\) should return GdImage\\|resource but returns (GdImage|resource)\\|false\\.$#"
33403340
count: 1
33413341
path: src/PhpSpreadsheet/Shared/Drawing.php
33423342

33433343
-
3344-
message: "#^Parameter \\#1 \\$fp of function feof expects resource, resource\\|false given\\.$#"
3344+
message: "#^Parameter \\#1 \\$(fp|stream) of function feof expects resource, resource\\|false given\\.$#"
33453345
count: 1
33463346
path: src/PhpSpreadsheet/Shared/Drawing.php
33473347

33483348
-
3349-
message: "#^Parameter \\#1 \\$fp of function fread expects resource, resource\\|false given\\.$#"
3349+
message: "#^Parameter \\#1 \\$(fp|stream) of function fread expects resource, resource\\|false given\\.$#"
33503350
count: 2
33513351
path: src/PhpSpreadsheet/Shared/Drawing.php
33523352

33533353
-
3354-
message: "#^Parameter \\#1 \\$im of function imagecolorallocate expects resource, resource\\|false given\\.$#"
3354+
message: "#^Parameter \\#1 \\$im(age)? of function imagecolorallocate expects (GdImage|resource), (GdImage|resource)\\|false given\\.$#"
33553355
count: 1
33563356
path: src/PhpSpreadsheet/Shared/Drawing.php
33573357

33583358
-
3359-
message: "#^Parameter \\#1 \\$im of function imagesetpixel expects resource, resource\\|false given\\.$#"
3359+
message: "#^Parameter \\#1 \\$im(age)? of function imagesetpixel expects (GdImage|resource), (GdImage|resource)\\|false given\\.$#"
33603360
count: 1
33613361
path: src/PhpSpreadsheet/Shared/Drawing.php
33623362

33633363
-
3364-
message: "#^Parameter \\#1 \\$x_size of function imagecreatetruecolor expects int, float\\|int given\\.$#"
3364+
message: "#^Parameter \\#1 \\$(x_size|width) of function imagecreatetruecolor expects int, float\\|int given\\.$#"
33653365
count: 1
33663366
path: src/PhpSpreadsheet/Shared/Drawing.php
33673367

33683368
-
3369-
message: "#^Parameter \\#2 \\$data of function unpack expects string, string\\|false given\\.$#"
3369+
message: "#^Parameter \\#2 \\$(data|string) of function unpack expects string, string\\|false given\\.$#"
33703370
count: 1
33713371
path: src/PhpSpreadsheet/Shared/Drawing.php
33723372

@@ -3376,7 +3376,7 @@ parameters:
33763376
path: src/PhpSpreadsheet/Shared/Drawing.php
33773377

33783378
-
3379-
message: "#^Parameter \\#2 \\$y_size of function imagecreatetruecolor expects int, float\\|int given\\.$#"
3379+
message: "#^Parameter \\#2 \\$(y_size|height) of function imagecreatetruecolor expects int, float\\|int given\\.$#"
33803380
count: 1
33813381
path: src/PhpSpreadsheet/Shared/Drawing.php
33823382

@@ -3396,7 +3396,7 @@ parameters:
33963396
path: src/PhpSpreadsheet/Shared/Drawing.php
33973397

33983398
-
3399-
message: "#^Parameter \\#4 \\$col of function imagesetpixel expects int, int\\|false given\\.$#"
3399+
message: "#^Parameter \\#4 \\$col(or)? of function imagesetpixel expects int, int\\|false given\\.$#"
34003400
count: 1
34013401
path: src/PhpSpreadsheet/Shared/Drawing.php
34023402

@@ -3596,7 +3596,7 @@ parameters:
35963596
path: src/PhpSpreadsheet/Shared/JAMA/Matrix.php
35973597

35983598
-
3599-
message: "#^Parameter \\#1 \\$str of function trim expects string, float\\|int given\\.$#"
3599+
message: "#^Parameter \\#1 \\$str(ing)? of function trim expects string, float\\|int given\\.$#"
36003600
count: 1
36013601
path: src/PhpSpreadsheet/Shared/JAMA/Matrix.php
36023602

@@ -3676,7 +3676,7 @@ parameters:
36763676
path: src/PhpSpreadsheet/Shared/OLE.php
36773677

36783678
-
3679-
message: "#^Parameter \\#2 \\$data of function unpack expects string, string\\|false given\\.$#"
3679+
message: "#^Parameter \\#2 \\$(data|string) of function unpack expects string, string\\|false given\\.$#"
36803680
count: 3
36813681
path: src/PhpSpreadsheet/Shared/OLE.php
36823682

@@ -3716,7 +3716,7 @@ parameters:
37163716
path: src/PhpSpreadsheet/Shared/OLE.php
37173717

37183718
-
3719-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, string given\\.$#"
3719+
message: "#^Parameter \\#1 \\$(var|value) of function count expects array\\|Countable, string given\\.$#"
37203720
count: 1
37213721
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
37223722

@@ -4061,7 +4061,7 @@ parameters:
40614061
path: src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php
40624062

40634063
-
4064-
message: "#^Parameter \\#2 \\.\\.\\.\\$args of function array_merge expects array, float given\\.$#"
4064+
message: "#^Parameter \\#2 \\.\\.\\.\\$(args|arrays) of function array_merge expects array, float given\\.$#"
40654065
count: 1
40664066
path: src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php
40674067

@@ -4361,7 +4361,7 @@ parameters:
43614361
path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php
43624362

43634363
-
4364-
message: "#^Parameter \\#2 \\$str of function explode expects string, string\\|null given\\.$#"
4364+
message: "#^Parameter \\#2 \\$str(ing)? of function explode expects string, string\\|null given\\.$#"
43654365
count: 1
43664366
path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php
43674367

@@ -4486,7 +4486,7 @@ parameters:
44864486
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
44874487

44884488
-
4489-
message: "#^Parameter \\#2 \\$str of function explode expects string, string\\|null given\\.$#"
4489+
message: "#^Parameter \\#2 \\$str(ing)? of function explode expects string, string\\|null given\\.$#"
44904490
count: 5
44914491
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
44924492

@@ -4581,7 +4581,7 @@ parameters:
45814581
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
45824582

45834583
-
4584-
message: "#^Parameter \\#1 \\$input of function array_splice expects array, ArrayObject\\<int, PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\> given\\.$#"
4584+
message: "#^Parameter \\#1 \\$(input|array) of function array_splice expects array, ArrayObject\\<int, PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\> given\\.$#"
45854585
count: 1
45864586
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
45874587

@@ -4606,7 +4606,7 @@ parameters:
46064606
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
46074607

46084608
-
4609-
message: "#^Parameter \\#2 \\$start of function substr expects int, int\\<0, max\\>\\|false given\\.$#"
4609+
message: "#^Parameter \\#2 \\$(start|offset) of function substr expects int, int(\\<0, max\\>)?\\|false given\\.$#"
46104610
count: 2
46114611
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
46124612

@@ -4931,12 +4931,12 @@ parameters:
49314931
path: src/PhpSpreadsheet/Writer/Html.php
49324932

49334933
-
4934-
message: "#^Parameter \\#1 \\$im of function imagepng expects resource, GdImage\\|resource given\\.$#"
4934+
message: "#^Parameter \\#1 \\$im(age)? of function imagepng expects (GdImage|resource), GdImage\\|resource given\\.$#"
49354935
count: 1
49364936
path: src/PhpSpreadsheet/Writer/Html.php
49374937

49384938
-
4939-
message: "#^Parameter \\#1 \\$str of function base64_encode expects string, string\\|false given\\.$#"
4939+
message: "#^Parameter \\#1 \\$str(ing)? of function base64_encode expects string, string\\|false given\\.$#"
49404940
count: 2
49414941
path: src/PhpSpreadsheet/Writer/Html.php
49424942

@@ -5066,12 +5066,12 @@ parameters:
50665066
path: src/PhpSpreadsheet/Writer/Xls.php
50675067

50685068
-
5069-
message: "#^Parameter \\#1 \\$im of function imagepng expects resource, GdImage\\|resource given\\.$#"
5069+
message: "#^Parameter \\#1 \\$im(age)? of function imagepng expects (GdImage|resource), GdImage\\|resource given\\.$#"
50705070
count: 1
50715071
path: src/PhpSpreadsheet/Writer/Xls.php
50725072

50735073
-
5074-
message: "#^Parameter \\#1 \\$im of function imagepng expects resource, resource\\|false given\\.$#"
5074+
message: "#^Parameter \\#1 \\$im(age)? of function imagepng expects (GdImage|resource), (GdImage|resource)\\|false given\\.$#"
50755075
count: 1
50765076
path: src/PhpSpreadsheet/Writer/Xls.php
50775077

@@ -5256,7 +5256,7 @@ parameters:
52565256
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
52575257

52585258
-
5259-
message: "#^Parameter \\#1 \\$im of function imagecolorat expects resource, GdImage\\|resource given\\.$#"
5259+
message: "#^Parameter \\#1 \\$im(age)? of function imagecolorat expects (GdImage|resource), GdImage\\|resource given\\.$#"
52605260
count: 1
52615261
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
52625262

@@ -5271,12 +5271,12 @@ parameters:
52715271
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
52725272

52735273
-
5274-
message: "#^Parameter \\#2 \\$col of function imagecolorsforindex expects int, int\\|false given\\.$#"
5274+
message: "#^Parameter \\#2 \\$col(or)? of function imagecolorsforindex expects int, int\\|false given\\.$#"
52755275
count: 1
52765276
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
52775277

52785278
-
5279-
message: "#^Parameter \\#2 \\$data of function unpack expects string, string\\|false given\\.$#"
5279+
message: "#^Parameter \\#2 \\$(data|string) of function unpack expects string, string\\|false given\\.$#"
52805280
count: 1
52815281
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
52825282

@@ -5286,7 +5286,7 @@ parameters:
52865286
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
52875287

52885288
-
5289-
message: "#^Parameter \\#2 \\$pieces of function implode expects array, array\\<int, string\\>\\|false given\\.$#"
5289+
message: "#^Parameter \\#2 \\$(pieces|array) of function implode expects array(\\|null)?, array\\<int, string\\>\\|false given\\.$#"
52905290
count: 1
52915291
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
52925292

@@ -5371,7 +5371,7 @@ parameters:
53715371
path: src/PhpSpreadsheet/Writer/Xlsx.php
53725372

53735373
-
5374-
message: "#^Parameter \\#1 \\$function of function call_user_func expects callable\\(\\)\\: mixed, string given\\.$#"
5374+
message: "#^Parameter \\#1 \\$(function|callback) of function call_user_func expects callable\\(\\)\\: mixed, string given\\.$#"
53755375
count: 1
53765376
path: src/PhpSpreadsheet/Writer/Xlsx.php
53775377

@@ -5850,51 +5850,11 @@ parameters:
58505850
count: 2
58515851
path: tests/PhpSpreadsheetTests/Functional/ConditionalStopIfTrueTest.php
58525852

5853-
-
5854-
message: "#^Cannot call method getUrl\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Hyperlink\\|null\\.$#"
5855-
count: 1
5856-
path: tests/PhpSpreadsheetTests/Functional/DrawingImageHyperlinkTest.php
5857-
5858-
-
5859-
message: "#^Parameter \\#1 \\$im of function imagecolorallocate expects resource, resource\\|false given\\.$#"
5860-
count: 1
5861-
path: tests/PhpSpreadsheetTests/Functional/DrawingImageHyperlinkTest.php
5862-
5863-
-
5864-
message: "#^Parameter \\#1 \\$im of function imagestring expects resource, resource\\|false given\\.$#"
5865-
count: 1
5866-
path: tests/PhpSpreadsheetTests/Functional/DrawingImageHyperlinkTest.php
5867-
5868-
-
5869-
message: "#^Parameter \\#1 \\$value of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\MemoryDrawing\\:\\:setImageResource\\(\\) expects GdImage\\|resource, resource\\|false given\\.$#"
5870-
count: 1
5871-
path: tests/PhpSpreadsheetTests/Functional/DrawingImageHyperlinkTest.php
5872-
5873-
-
5874-
message: "#^Parameter \\#6 \\$col of function imagestring expects int, int\\|false given\\.$#"
5875-
count: 1
5876-
path: tests/PhpSpreadsheetTests/Functional/DrawingImageHyperlinkTest.php
5877-
58785853
-
58795854
message: "#^Cannot call method getPageSetup\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
58805855
count: 5
58815856
path: tests/PhpSpreadsheetTests/Functional/PrintAreaTest.php
58825857

5883-
-
5884-
message: "#^Cannot access offset 'size' on array\\{0\\: int, 1\\: int, 2\\: int, 3\\: int, 4\\: int, 5\\: int, 6\\: int, 7\\: int, \\.\\.\\.\\}\\|false\\.$#"
5885-
count: 2
5886-
path: tests/PhpSpreadsheetTests/Functional/StreamTest.php
5887-
5888-
-
5889-
message: "#^Parameter \\#1 \\$filename of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\IWriter\\:\\:save\\(\\) expects resource\\|string, resource\\|false given\\.$#"
5890-
count: 1
5891-
path: tests/PhpSpreadsheetTests/Functional/StreamTest.php
5892-
5893-
-
5894-
message: "#^Parameter \\#1 \\$fp of function fstat expects resource, resource\\|false given\\.$#"
5895-
count: 1
5896-
path: tests/PhpSpreadsheetTests/Functional/StreamTest.php
5897-
58985858
-
58995859
message: "#^Parameter \\#1 \\$expected of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) expects class\\-string\\<object\\>, string given\\.$#"
59005860
count: 3
@@ -6050,26 +6010,6 @@ parameters:
60506010
count: 1
60516011
path: tests/PhpSpreadsheetTests/Worksheet/AutoFilter/ColumnTest.php
60526012

6053-
-
6054-
message: "#^Parameter \\#1 \\$im of function imagecolorallocate expects resource, resource\\|false given\\.$#"
6055-
count: 1
6056-
path: tests/PhpSpreadsheetTests/Worksheet/DrawingTest.php
6057-
6058-
-
6059-
message: "#^Parameter \\#1 \\$im of function imagestring expects resource, resource\\|false given\\.$#"
6060-
count: 1
6061-
path: tests/PhpSpreadsheetTests/Worksheet/DrawingTest.php
6062-
6063-
-
6064-
message: "#^Parameter \\#1 \\$value of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\MemoryDrawing\\:\\:setImageResource\\(\\) expects GdImage\\|resource, resource\\|false given\\.$#"
6065-
count: 1
6066-
path: tests/PhpSpreadsheetTests/Worksheet/DrawingTest.php
6067-
6068-
-
6069-
message: "#^Parameter \\#6 \\$col of function imagestring expects int, int\\|false given\\.$#"
6070-
count: 1
6071-
path: tests/PhpSpreadsheetTests/Worksheet/DrawingTest.php
6072-
60736013
-
60746014
message: "#^Parameter \\#2 \\$rowIndex of class PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowCellIterator constructor expects int, string given\\.$#"
60756015
count: 1

0 commit comments

Comments
 (0)