Skip to content

Commit cd84020

Browse files
authored
Xlsx Reader Better Namespace Handling Phase 1 Try2 (#2173)
* Xlsx Reader Better Namespace Handling Phase 1 Try2 This is a replacement for #2088, which has run into merge conflicts. I will close that PR in the near future, however the comments in that PR may prove useful for this one. While that PR has been in draft status all along, I am marking this one as ready. I will gladly add additional tests (and, of course, make code changes) that anyone has to suggest, but, with my most recent test files which I will describe in a separate comment, I have no further ideas on useful additions. As mentioned in the earlier ticket, this is a risky change. But, as has been demonstrated, delaying it comes with its own set of risks. It would be helpful to have a temporary moratorium on changes to Reader/Xlsx until this change is merged. The original commit message follows. 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 #860 (comment) in issue #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 #2067 PR #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.
1 parent 034ac5a commit cd84020

26 files changed

+1248
-697
lines changed

phpstan-baseline.neon

-195
Original file line numberDiff line numberDiff line change
@@ -2925,21 +2925,6 @@ parameters:
29252925
count: 1
29262926
path: src/PhpSpreadsheet/Reader/Xls/RC4.php
29272927

2928-
-
2929-
message: "#^Cannot access property \\$Relationship on SimpleXMLElement\\|false\\.$#"
2930-
count: 12
2931-
path: src/PhpSpreadsheet/Reader/Xlsx.php
2932-
2933-
-
2934-
message: "#^Cannot access property \\$sheets on SimpleXMLElement\\|false\\.$#"
2935-
count: 6
2936-
path: src/PhpSpreadsheet/Reader/Xlsx.php
2937-
2938-
-
2939-
message: "#^Cannot call method registerXPathNamespace\\(\\) on SimpleXMLElement\\|false\\.$#"
2940-
count: 4
2941-
path: src/PhpSpreadsheet/Reader/Xlsx.php
2942-
29432928
-
29442929
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\:\\:castToBoolean\\(\\) has no return typehint specified\\.$#"
29452930
count: 1
@@ -3010,86 +2995,16 @@ parameters:
30102995
count: 1
30112996
path: src/PhpSpreadsheet/Reader/Xlsx.php
30122997

3013-
-
3014-
message: "#^Offset 'name' does not exist on SimpleXMLElement\\|null\\.$#"
3015-
count: 2
3016-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3017-
3018-
-
3019-
message: "#^Cannot call method xpath\\(\\) on SimpleXMLElement\\|false\\.$#"
3020-
count: 4
3021-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3022-
30232998
-
30242999
message: "#^Parameter \\#1 \\$is of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\:\\:parseRichText\\(\\) expects SimpleXMLElement\\|null, object given\\.$#"
30253000
count: 1
30263001
path: src/PhpSpreadsheet/Reader/Xlsx.php
30273002

3028-
-
3029-
message: "#^Parameter \\#1 \\$styleXml of class PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Styles constructor expects SimpleXMLElement, SimpleXMLElement\\|false given\\.$#"
3030-
count: 1
3031-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3032-
3033-
-
3034-
message: "#^Cannot access property \\$workbookPr on SimpleXMLElement\\|false\\.$#"
3035-
count: 2
3036-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3037-
3038-
-
3039-
message: "#^Parameter \\#2 \\$xmlWorkbook of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\:\\:readProtection\\(\\) expects SimpleXMLElement, SimpleXMLElement\\|false given\\.$#"
3040-
count: 1
3041-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3042-
3043-
-
3044-
message: "#^Parameter \\#1 \\$relsWorksheet of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Hyperlinks\\:\\:readHyperlinks\\(\\) expects SimpleXMLElement, SimpleXMLElement\\|false given\\.$#"
3045-
count: 1
3046-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3047-
3048-
-
3049-
message: "#^Cannot access property \\$authors on SimpleXMLElement\\|false\\.$#"
3050-
count: 1
3051-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3052-
3053-
-
3054-
message: "#^Cannot access property \\$commentList on SimpleXMLElement\\|false\\.$#"
3055-
count: 1
3056-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3057-
3058-
-
3059-
message: "#^Argument of an invalid type array\\<SimpleXMLElement\\>\\|false supplied for foreach, only iterables are supported\\.$#"
3060-
count: 2
3061-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3062-
30633003
-
30643004
message: "#^Negated boolean expression is always true\\.$#"
30653005
count: 1
30663006
path: src/PhpSpreadsheet/Reader/Xlsx.php
30673007

3068-
-
3069-
message: "#^Cannot access property \\$drawing on SimpleXMLElement\\|false\\.$#"
3070-
count: 2
3071-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3072-
3073-
-
3074-
message: "#^Cannot call method children\\(\\) on SimpleXMLElement\\|false\\.$#"
3075-
count: 2
3076-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3077-
3078-
-
3079-
message: "#^Cannot call method count\\(\\) on SimpleXMLElement\\|false\\.$#"
3080-
count: 1
3081-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3082-
3083-
-
3084-
message: "#^Cannot call method asXML\\(\\) on SimpleXMLElement\\|false\\.$#"
3085-
count: 1
3086-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3087-
3088-
-
3089-
message: "#^Cannot access property \\$definedNames on SimpleXMLElement\\|false\\.$#"
3090-
count: 4
3091-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3092-
30933008
-
30943009
message: "#^Argument of an invalid type array\\<int, string\\>\\|false supplied for foreach, only iterables are supported\\.$#"
30953010
count: 1
@@ -3105,26 +3020,6 @@ parameters:
31053020
count: 1
31063021
path: src/PhpSpreadsheet/Reader/Xlsx.php
31073022

3108-
-
3109-
message: "#^Cannot access property \\$bookViews on SimpleXMLElement\\|false\\.$#"
3110-
count: 1
3111-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3112-
3113-
-
3114-
message: "#^Cannot access property \\$Default on SimpleXMLElement\\|false\\.$#"
3115-
count: 1
3116-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3117-
3118-
-
3119-
message: "#^Cannot access property \\$Override on SimpleXMLElement\\|false\\.$#"
3120-
count: 1
3121-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3122-
3123-
-
3124-
message: "#^Parameter \\#1 \\$chartElements of static method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Chart\\:\\:readChart\\(\\) expects SimpleXMLElement, SimpleXMLElement\\|false given\\.$#"
3125-
count: 1
3126-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3127-
31283023
-
31293024
message: "#^Cannot call method addChart\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
31303025
count: 1
@@ -3265,11 +3160,6 @@ parameters:
32653160
count: 1
32663161
path: src/PhpSpreadsheet/Reader/Xlsx.php
32673162

3268-
-
3269-
message: "#^Offset 'id' does not exist on SimpleXMLElement\\|null\\.$#"
3270-
count: 1
3271-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3272-
32733163
-
32743164
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\:\\:readFormControlProperties\\(\\) has parameter \\$dir with no typehint specified\\.$#"
32753165
count: 1
@@ -3700,66 +3590,6 @@ parameters:
37003590
count: 1
37013591
path: src/PhpSpreadsheet/Reader/Xlsx/PageSetup.php
37023592

3703-
-
3704-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:\\$securityScanner has no typehint specified\\.$#"
3705-
count: 1
3706-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3707-
3708-
-
3709-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:\\$docProps has no typehint specified\\.$#"
3710-
count: 1
3711-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3712-
3713-
-
3714-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:extractPropertyData\\(\\) has no return typehint specified\\.$#"
3715-
count: 1
3716-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3717-
3718-
-
3719-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:extractPropertyData\\(\\) has parameter \\$propertyData with no typehint specified\\.$#"
3720-
count: 1
3721-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3722-
3723-
-
3724-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:readCoreProperties\\(\\) has parameter \\$propertyData with no typehint specified\\.$#"
3725-
count: 1
3726-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3727-
3728-
-
3729-
message: "#^Call to an undefined method object\\:\\:registerXPathNamespace\\(\\)\\.$#"
3730-
count: 3
3731-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3732-
3733-
-
3734-
message: "#^Call to an undefined method object\\:\\:xpath\\(\\)\\.$#"
3735-
count: 9
3736-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3737-
3738-
-
3739-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:readExtendedProperties\\(\\) has parameter \\$propertyData with no typehint specified\\.$#"
3740-
count: 1
3741-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3742-
3743-
-
3744-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:readCustomProperties\\(\\) has parameter \\$propertyData with no typehint specified\\.$#"
3745-
count: 1
3746-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3747-
3748-
-
3749-
message: "#^Argument of an invalid type object supplied for foreach, only iterables are supported\\.$#"
3750-
count: 1
3751-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3752-
3753-
-
3754-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:getArrayItem\\(\\) has no return typehint specified\\.$#"
3755-
count: 1
3756-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3757-
3758-
-
3759-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:getArrayItem\\(\\) has parameter \\$key with no typehint specified\\.$#"
3760-
count: 1
3761-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3762-
37633593
-
37643594
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\SheetViewOptions\\:\\:\\$worksheet has no typehint specified\\.$#"
37653595
count: 1
@@ -3770,16 +3600,6 @@ parameters:
37703600
count: 1
37713601
path: src/PhpSpreadsheet/Reader/Xlsx/SheetViewOptions.php
37723602

3773-
-
3774-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\SheetViews\\:\\:\\$sheetViewXml has no typehint specified\\.$#"
3775-
count: 1
3776-
path: src/PhpSpreadsheet/Reader/Xlsx/SheetViews.php
3777-
3778-
-
3779-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\SheetViews\\:\\:\\$worksheet has no typehint specified\\.$#"
3780-
count: 1
3781-
path: src/PhpSpreadsheet/Reader/Xlsx/SheetViews.php
3782-
37833603
-
37843604
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Styles\\:\\:\\$styles has no typehint specified\\.$#"
37853605
count: 1
@@ -3810,11 +3630,6 @@ parameters:
38103630
count: 1
38113631
path: src/PhpSpreadsheet/Reader/Xlsx/Styles.php
38123632

3813-
-
3814-
message: "#^Cannot call method count\\(\\) on SimpleXMLElement\\|null\\.$#"
3815-
count: 1
3816-
path: src/PhpSpreadsheet/Reader/Xlsx/Styles.php
3817-
38183633
-
38193634
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Styles\\:\\:readStyle\\(\\) has parameter \\$style with no typehint specified\\.$#"
38203635
count: 1
@@ -3925,11 +3740,6 @@ parameters:
39253740
count: 1
39263741
path: src/PhpSpreadsheet/ReferenceHelper.php
39273742

3928-
-
3929-
message: "#^Parameter \\#1 \\$pCellRange of method PhpOffice\\\\PhpSpreadsheet\\\\ReferenceHelper\\:\\:updateCellReference\\(\\) expects string, string\\|null given\\.$#"
3930-
count: 1
3931-
path: src/PhpSpreadsheet/ReferenceHelper.php
3932-
39333743
-
39343744
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, string\\|null given\\.$#"
39353745
count: 1
@@ -5485,11 +5295,6 @@ parameters:
54855295
count: 1
54865296
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
54875297

5488-
-
5489-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\:\\:getFreezePane\\(\\) should return string but returns string\\|null\\.$#"
5490-
count: 1
5491-
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
5492-
54935298
-
54945299
message: "#^Parameter \\#1 \\$row of method PhpOffice\\\\PhpSpreadsheet\\\\Collection\\\\Cells\\:\\:removeRow\\(\\) expects string, int given\\.$#"
54955300
count: 2

0 commit comments

Comments
 (0)