Skip to content

Commit 5687a53

Browse files
committed
Xlsx Reader Better Namespace Handling Phase 1
There have been a number of issues concerning the handling of legitimate but unexpected namespace prefixes in Xlsx spreadsheets created by software other than Excel and PhpSpreadsheet/PhpExcel.I have studied them, but, till now, have not had a good idea on how to act on them. A recent comment PHPOffice#860 (comment) in issue PHPOffice#860 by @IMSoP has triggered an idea about how to proceed. Gnumeric Reader was recently changed to handle namespaces better. Using that as a model, this PR begins the process of doing the same for Xlsx. Xlsx is much larger and more complicated than Gnumeric, hence the need to tackle it in multiple phases. I believe that this PR handles all of: - listWorkSheetNames - listWorkSheetInfo. Note that there was a bug in this function which would cause it to count only used columns rather than all columns. That bug is corrected. - active sheet - selected cell and top left cell - cell content (formulas, numbers, text) - hyperlinks - comments (partial - see below) This PR does not address: - styles - images and charts - VBA and ribbons - many other items, I'm sure The issue for non-standard namespacing till now has been the use of unexpected prefixes. While I was working on this change, @Lambik introduced issue PHPOffice#2067 PR PHPOffice#2068 which introduced a completely different problem - the use of unexpected URLs. That PR and the issue associated with it were quite well documented, including the supplying of a test file and tests for it. I asked if I could take a look to see if it could be integrated with my change, and the result seems to be yes, so those changes are also part of this PR. While adding a comment to my test file, I discovered that Microsoft had added "threaded comments" as a new feature. I believe these are not yet supported by PhpSpreadsheet, and I am not going to add it, at least not now. I believe that, among other things, this will make identifying the author of a comment more difficult. Although there are a number of Phpstan baseline changes as part of this PR, I did not attempt to resolve all Phpstan reports for Reader/Xlsx. Nor did I do anything to increase coverage. This change is already large and complex enough without those efforts. I will add more detail as comments after I push this change.
1 parent b05dc31 commit 5687a53

26 files changed

+1018
-681
lines changed

phpstan-baseline.neon

-215
Original file line numberDiff line numberDiff line change
@@ -3735,21 +3735,6 @@ parameters:
37353735
count: 1
37363736
path: src/PhpSpreadsheet/Reader/Xls/Style/FillPattern.php
37373737

3738-
-
3739-
message: "#^Cannot access property \\$Relationship on SimpleXMLElement\\|false\\.$#"
3740-
count: 12
3741-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3742-
3743-
-
3744-
message: "#^Cannot access property \\$sheets on SimpleXMLElement\\|false\\.$#"
3745-
count: 6
3746-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3747-
3748-
-
3749-
message: "#^Cannot call method registerXPathNamespace\\(\\) on SimpleXMLElement\\|false\\.$#"
3750-
count: 4
3751-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3752-
37533738
-
37543739
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\:\\:castToBoolean\\(\\) has no return typehint specified\\.$#"
37553740
count: 1
@@ -3825,81 +3810,16 @@ parameters:
38253810
count: 2
38263811
path: src/PhpSpreadsheet/Reader/Xlsx.php
38273812

3828-
-
3829-
message: "#^Cannot call method xpath\\(\\) on SimpleXMLElement\\|false\\.$#"
3830-
count: 4
3831-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3832-
38333813
-
38343814
message: "#^Parameter \\#1 \\$is of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\:\\:parseRichText\\(\\) expects SimpleXMLElement\\|null, object given\\.$#"
38353815
count: 1
38363816
path: src/PhpSpreadsheet/Reader/Xlsx.php
38373817

3838-
-
3839-
message: "#^Parameter \\#1 \\$styleXml of class PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Styles constructor expects SimpleXMLElement, SimpleXMLElement\\|false given\\.$#"
3840-
count: 1
3841-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3842-
3843-
-
3844-
message: "#^Cannot access property \\$workbookPr on SimpleXMLElement\\|false\\.$#"
3845-
count: 2
3846-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3847-
3848-
-
3849-
message: "#^Parameter \\#2 \\$xmlWorkbook of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\:\\:readProtection\\(\\) expects SimpleXMLElement, SimpleXMLElement\\|false given\\.$#"
3850-
count: 1
3851-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3852-
3853-
-
3854-
message: "#^Parameter \\#1 \\$relsWorksheet of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Hyperlinks\\:\\:readHyperlinks\\(\\) expects SimpleXMLElement, SimpleXMLElement\\|false given\\.$#"
3855-
count: 1
3856-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3857-
3858-
-
3859-
message: "#^Cannot access property \\$authors on SimpleXMLElement\\|false\\.$#"
3860-
count: 1
3861-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3862-
3863-
-
3864-
message: "#^Cannot access property \\$commentList on SimpleXMLElement\\|false\\.$#"
3865-
count: 1
3866-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3867-
3868-
-
3869-
message: "#^Argument of an invalid type array\\<SimpleXMLElement\\>\\|false supplied for foreach, only iterables are supported\\.$#"
3870-
count: 2
3871-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3872-
38733818
-
38743819
message: "#^Negated boolean expression is always true\\.$#"
38753820
count: 1
38763821
path: src/PhpSpreadsheet/Reader/Xlsx.php
38773822

3878-
-
3879-
message: "#^Cannot access property \\$drawing on SimpleXMLElement\\|false\\.$#"
3880-
count: 2
3881-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3882-
3883-
-
3884-
message: "#^Cannot call method children\\(\\) on SimpleXMLElement\\|false\\.$#"
3885-
count: 2
3886-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3887-
3888-
-
3889-
message: "#^Cannot call method count\\(\\) on SimpleXMLElement\\|false\\.$#"
3890-
count: 1
3891-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3892-
3893-
-
3894-
message: "#^Cannot call method asXML\\(\\) on SimpleXMLElement\\|false\\.$#"
3895-
count: 1
3896-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3897-
3898-
-
3899-
message: "#^Cannot access property \\$definedNames on SimpleXMLElement\\|false\\.$#"
3900-
count: 4
3901-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3902-
39033823
-
39043824
message: "#^Argument of an invalid type array\\<int, string\\>\\|false supplied for foreach, only iterables are supported\\.$#"
39053825
count: 1
@@ -3915,26 +3835,6 @@ parameters:
39153835
count: 1
39163836
path: src/PhpSpreadsheet/Reader/Xlsx.php
39173837

3918-
-
3919-
message: "#^Cannot access property \\$bookViews on SimpleXMLElement\\|false\\.$#"
3920-
count: 1
3921-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3922-
3923-
-
3924-
message: "#^Cannot access property \\$Default on SimpleXMLElement\\|false\\.$#"
3925-
count: 1
3926-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3927-
3928-
-
3929-
message: "#^Cannot access property \\$Override on SimpleXMLElement\\|false\\.$#"
3930-
count: 1
3931-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3932-
3933-
-
3934-
message: "#^Parameter \\#1 \\$chartElements of static method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Chart\\:\\:readChart\\(\\) expects SimpleXMLElement, SimpleXMLElement\\|false given\\.$#"
3935-
count: 1
3936-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3937-
39383838
-
39393839
message: "#^Cannot call method addChart\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
39403840
count: 1
@@ -4535,66 +4435,6 @@ parameters:
45354435
count: 1
45364436
path: src/PhpSpreadsheet/Reader/Xlsx/PageSetup.php
45374437

4538-
-
4539-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:\\$securityScanner has no typehint specified\\.$#"
4540-
count: 1
4541-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
4542-
4543-
-
4544-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:\\$docProps has no typehint specified\\.$#"
4545-
count: 1
4546-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
4547-
4548-
-
4549-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:extractPropertyData\\(\\) has no return typehint specified\\.$#"
4550-
count: 1
4551-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
4552-
4553-
-
4554-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:extractPropertyData\\(\\) has parameter \\$propertyData with no typehint specified\\.$#"
4555-
count: 1
4556-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
4557-
4558-
-
4559-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:readCoreProperties\\(\\) has parameter \\$propertyData with no typehint specified\\.$#"
4560-
count: 1
4561-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
4562-
4563-
-
4564-
message: "#^Call to an undefined method object\\:\\:registerXPathNamespace\\(\\)\\.$#"
4565-
count: 3
4566-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
4567-
4568-
-
4569-
message: "#^Call to an undefined method object\\:\\:xpath\\(\\)\\.$#"
4570-
count: 9
4571-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
4572-
4573-
-
4574-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:readExtendedProperties\\(\\) has parameter \\$propertyData with no typehint specified\\.$#"
4575-
count: 1
4576-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
4577-
4578-
-
4579-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:readCustomProperties\\(\\) has parameter \\$propertyData with no typehint specified\\.$#"
4580-
count: 1
4581-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
4582-
4583-
-
4584-
message: "#^Argument of an invalid type object supplied for foreach, only iterables are supported\\.$#"
4585-
count: 1
4586-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
4587-
4588-
-
4589-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:getArrayItem\\(\\) has no return typehint specified\\.$#"
4590-
count: 1
4591-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
4592-
4593-
-
4594-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:getArrayItem\\(\\) has parameter \\$key with no typehint specified\\.$#"
4595-
count: 1
4596-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
4597-
45984438
-
45994439
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\SheetViewOptions\\:\\:\\$worksheet has no typehint specified\\.$#"
46004440
count: 1
@@ -4605,16 +4445,6 @@ parameters:
46054445
count: 1
46064446
path: src/PhpSpreadsheet/Reader/Xlsx/SheetViewOptions.php
46074447

4608-
-
4609-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\SheetViews\\:\\:\\$sheetViewXml has no typehint specified\\.$#"
4610-
count: 1
4611-
path: src/PhpSpreadsheet/Reader/Xlsx/SheetViews.php
4612-
4613-
-
4614-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\SheetViews\\:\\:\\$worksheet has no typehint specified\\.$#"
4615-
count: 1
4616-
path: src/PhpSpreadsheet/Reader/Xlsx/SheetViews.php
4617-
46184448
-
46194449
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Styles\\:\\:\\$styles has no typehint specified\\.$#"
46204450
count: 1
@@ -4820,11 +4650,6 @@ parameters:
48204650
count: 1
48214651
path: src/PhpSpreadsheet/ReferenceHelper.php
48224652

4823-
-
4824-
message: "#^Parameter \\#1 \\$pCellRange of method PhpOffice\\\\PhpSpreadsheet\\\\ReferenceHelper\\:\\:updateCellReference\\(\\) expects string, string\\|null given\\.$#"
4825-
count: 1
4826-
path: src/PhpSpreadsheet/ReferenceHelper.php
4827-
48284653
-
48294654
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, string\\|null given\\.$#"
48304655
count: 1
@@ -6680,11 +6505,6 @@ parameters:
66806505
count: 1
66816506
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
66826507

6683-
-
6684-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\:\\:getFreezePane\\(\\) should return string but returns string\\|null\\.$#"
6685-
count: 1
6686-
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
6687-
66886508
-
66896509
message: "#^Parameter \\#1 \\$row of method PhpOffice\\\\PhpSpreadsheet\\\\Collection\\\\Cells\\:\\:removeRow\\(\\) expects string, int given\\.$#"
66906510
count: 2
@@ -8395,16 +8215,6 @@ parameters:
83958215
count: 1
83968216
path: tests/PhpSpreadsheetTests/Reader/Xlsx/AutoFilterTest.php
83978217

8398-
-
8399-
message: "#^Function PhpOffice\\\\PhpSpreadsheetTests\\\\Reader\\\\getTitleText\\(\\) has no return typehint specified\\.$#"
8400-
count: 1
8401-
path: tests/PhpSpreadsheetTests/Reader/Xlsx/ChartsTitleTest.php
8402-
8403-
-
8404-
message: "#^Function PhpOffice\\\\PhpSpreadsheetTests\\\\Reader\\\\getTitleText\\(\\) has parameter \\$title with no typehint specified\\.$#"
8405-
count: 1
8406-
path: tests/PhpSpreadsheetTests/Reader/Xlsx/ChartsTitleTest.php
8407-
84088218
-
84098219
message: "#^Cannot call method setMinimumConditionalFormatValueObject\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\ConditionalFormatting\\\\ConditionalDataBar\\|null\\.$#"
84108220
count: 1
@@ -8435,31 +8245,6 @@ parameters:
84358245
count: 1
84368246
path: tests/PhpSpreadsheetTests/Reader/Xlsx/ConditionalFormattingDataBarXlsxTest.php
84378247

8438-
-
8439-
message: "#^Cannot call method getRowHeight\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
8440-
count: 1
8441-
path: tests/PhpSpreadsheetTests/Reader/XlsxTest.php
8442-
8443-
-
8444-
message: "#^Cannot call method getVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
8445-
count: 1
8446-
path: tests/PhpSpreadsheetTests/Reader/XlsxTest.php
8447-
8448-
-
8449-
message: "#^Cannot call method getWidth\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
8450-
count: 1
8451-
path: tests/PhpSpreadsheetTests/Reader/XlsxTest.php
8452-
8453-
-
8454-
message: "#^Cannot call method getVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
8455-
count: 1
8456-
path: tests/PhpSpreadsheetTests/Reader/XlsxTest.php
8457-
8458-
-
8459-
message: "#^Method PhpOffice\\\\PhpSpreadsheetTests\\\\Reader\\\\XlsxTest\\:\\:testStripsWhiteSpaceFromStyleString\\(\\) has parameter \\$string with no typehint specified\\.$#"
8460-
count: 1
8461-
path: tests/PhpSpreadsheetTests/Reader/XlsxTest.php
8462-
84638248
-
84648249
message: "#^Method PhpOffice\\\\PhpSpreadsheetTests\\\\Reader\\\\Xml\\\\XmlTest\\:\\:testInvalidSimpleXML\\(\\) has parameter \\$filename with no typehint specified\\.$#"
84658250
count: 1

0 commit comments

Comments
 (0)