Skip to content

Commit 7694ad8

Browse files
committed
Xlsx Reader Better Namespace Handling Phase 1 Try2
This is a replacement for PHPOffice#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 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 83c0f02 commit 7694ad8

25 files changed

+1244
-696
lines changed

phpstan-baseline.neon

-195
Original file line numberDiff line numberDiff line change
@@ -2935,21 +2935,6 @@ parameters:
29352935
count: 1
29362936
path: src/PhpSpreadsheet/Reader/Xls/RC4.php
29372937

2938-
-
2939-
message: "#^Cannot access property \\$Relationship on SimpleXMLElement\\|false\\.$#"
2940-
count: 12
2941-
path: src/PhpSpreadsheet/Reader/Xlsx.php
2942-
2943-
-
2944-
message: "#^Cannot access property \\$sheets on SimpleXMLElement\\|false\\.$#"
2945-
count: 6
2946-
path: src/PhpSpreadsheet/Reader/Xlsx.php
2947-
2948-
-
2949-
message: "#^Cannot call method registerXPathNamespace\\(\\) on SimpleXMLElement\\|false\\.$#"
2950-
count: 4
2951-
path: src/PhpSpreadsheet/Reader/Xlsx.php
2952-
29532938
-
29542939
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\:\\:castToBoolean\\(\\) has no return typehint specified\\.$#"
29552940
count: 1
@@ -3020,86 +3005,16 @@ parameters:
30203005
count: 1
30213006
path: src/PhpSpreadsheet/Reader/Xlsx.php
30223007

3023-
-
3024-
message: "#^Offset 'name' does not exist on SimpleXMLElement\\|null\\.$#"
3025-
count: 2
3026-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3027-
3028-
-
3029-
message: "#^Cannot call method xpath\\(\\) on SimpleXMLElement\\|false\\.$#"
3030-
count: 4
3031-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3032-
30333008
-
30343009
message: "#^Parameter \\#1 \\$is of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\:\\:parseRichText\\(\\) expects SimpleXMLElement\\|null, object given\\.$#"
30353010
count: 1
30363011
path: src/PhpSpreadsheet/Reader/Xlsx.php
30373012

3038-
-
3039-
message: "#^Parameter \\#1 \\$styleXml of class PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Styles constructor expects SimpleXMLElement, SimpleXMLElement\\|false given\\.$#"
3040-
count: 1
3041-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3042-
3043-
-
3044-
message: "#^Cannot access property \\$workbookPr on SimpleXMLElement\\|false\\.$#"
3045-
count: 2
3046-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3047-
3048-
-
3049-
message: "#^Parameter \\#2 \\$xmlWorkbook of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\:\\:readProtection\\(\\) expects SimpleXMLElement, SimpleXMLElement\\|false given\\.$#"
3050-
count: 1
3051-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3052-
3053-
-
3054-
message: "#^Parameter \\#1 \\$relsWorksheet of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Hyperlinks\\:\\:readHyperlinks\\(\\) expects SimpleXMLElement, SimpleXMLElement\\|false given\\.$#"
3055-
count: 1
3056-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3057-
3058-
-
3059-
message: "#^Cannot access property \\$authors on SimpleXMLElement\\|false\\.$#"
3060-
count: 1
3061-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3062-
3063-
-
3064-
message: "#^Cannot access property \\$commentList on SimpleXMLElement\\|false\\.$#"
3065-
count: 1
3066-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3067-
3068-
-
3069-
message: "#^Argument of an invalid type array\\<SimpleXMLElement\\>\\|false supplied for foreach, only iterables are supported\\.$#"
3070-
count: 2
3071-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3072-
30733013
-
30743014
message: "#^Negated boolean expression is always true\\.$#"
30753015
count: 1
30763016
path: src/PhpSpreadsheet/Reader/Xlsx.php
30773017

3078-
-
3079-
message: "#^Cannot access property \\$drawing on SimpleXMLElement\\|false\\.$#"
3080-
count: 2
3081-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3082-
3083-
-
3084-
message: "#^Cannot call method children\\(\\) on SimpleXMLElement\\|false\\.$#"
3085-
count: 2
3086-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3087-
3088-
-
3089-
message: "#^Cannot call method count\\(\\) on SimpleXMLElement\\|false\\.$#"
3090-
count: 1
3091-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3092-
3093-
-
3094-
message: "#^Cannot call method asXML\\(\\) on SimpleXMLElement\\|false\\.$#"
3095-
count: 1
3096-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3097-
3098-
-
3099-
message: "#^Cannot access property \\$definedNames on SimpleXMLElement\\|false\\.$#"
3100-
count: 4
3101-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3102-
31033018
-
31043019
message: "#^Argument of an invalid type array\\<int, string\\>\\|false supplied for foreach, only iterables are supported\\.$#"
31053020
count: 1
@@ -3115,26 +3030,6 @@ parameters:
31153030
count: 1
31163031
path: src/PhpSpreadsheet/Reader/Xlsx.php
31173032

3118-
-
3119-
message: "#^Cannot access property \\$bookViews on SimpleXMLElement\\|false\\.$#"
3120-
count: 1
3121-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3122-
3123-
-
3124-
message: "#^Cannot access property \\$Default on SimpleXMLElement\\|false\\.$#"
3125-
count: 1
3126-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3127-
3128-
-
3129-
message: "#^Cannot access property \\$Override on SimpleXMLElement\\|false\\.$#"
3130-
count: 1
3131-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3132-
3133-
-
3134-
message: "#^Parameter \\#1 \\$chartElements of static method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Chart\\:\\:readChart\\(\\) expects SimpleXMLElement, SimpleXMLElement\\|false given\\.$#"
3135-
count: 1
3136-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3137-
31383033
-
31393034
message: "#^Cannot call method addChart\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
31403035
count: 1
@@ -3275,11 +3170,6 @@ parameters:
32753170
count: 1
32763171
path: src/PhpSpreadsheet/Reader/Xlsx.php
32773172

3278-
-
3279-
message: "#^Offset 'id' does not exist on SimpleXMLElement\\|null\\.$#"
3280-
count: 1
3281-
path: src/PhpSpreadsheet/Reader/Xlsx.php
3282-
32833173
-
32843174
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\:\\:readFormControlProperties\\(\\) has parameter \\$dir with no typehint specified\\.$#"
32853175
count: 1
@@ -3710,66 +3600,6 @@ parameters:
37103600
count: 1
37113601
path: src/PhpSpreadsheet/Reader/Xlsx/PageSetup.php
37123602

3713-
-
3714-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:\\$securityScanner has no typehint specified\\.$#"
3715-
count: 1
3716-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3717-
3718-
-
3719-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:\\$docProps has no typehint specified\\.$#"
3720-
count: 1
3721-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3722-
3723-
-
3724-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:extractPropertyData\\(\\) has no return typehint specified\\.$#"
3725-
count: 1
3726-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3727-
3728-
-
3729-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:extractPropertyData\\(\\) has parameter \\$propertyData with no typehint specified\\.$#"
3730-
count: 1
3731-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3732-
3733-
-
3734-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:readCoreProperties\\(\\) has parameter \\$propertyData with no typehint specified\\.$#"
3735-
count: 1
3736-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3737-
3738-
-
3739-
message: "#^Call to an undefined method object\\:\\:registerXPathNamespace\\(\\)\\.$#"
3740-
count: 3
3741-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3742-
3743-
-
3744-
message: "#^Call to an undefined method object\\:\\:xpath\\(\\)\\.$#"
3745-
count: 9
3746-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3747-
3748-
-
3749-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:readExtendedProperties\\(\\) has parameter \\$propertyData with no typehint specified\\.$#"
3750-
count: 1
3751-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3752-
3753-
-
3754-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:readCustomProperties\\(\\) has parameter \\$propertyData with no typehint specified\\.$#"
3755-
count: 1
3756-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3757-
3758-
-
3759-
message: "#^Argument of an invalid type object supplied for foreach, only iterables are supported\\.$#"
3760-
count: 1
3761-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3762-
3763-
-
3764-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:getArrayItem\\(\\) has no return typehint specified\\.$#"
3765-
count: 1
3766-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3767-
3768-
-
3769-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Properties\\:\\:getArrayItem\\(\\) has parameter \\$key with no typehint specified\\.$#"
3770-
count: 1
3771-
path: src/PhpSpreadsheet/Reader/Xlsx/Properties.php
3772-
37733603
-
37743604
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\SheetViewOptions\\:\\:\\$worksheet has no typehint specified\\.$#"
37753605
count: 1
@@ -3780,16 +3610,6 @@ parameters:
37803610
count: 1
37813611
path: src/PhpSpreadsheet/Reader/Xlsx/SheetViewOptions.php
37823612

3783-
-
3784-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\SheetViews\\:\\:\\$sheetViewXml has no typehint specified\\.$#"
3785-
count: 1
3786-
path: src/PhpSpreadsheet/Reader/Xlsx/SheetViews.php
3787-
3788-
-
3789-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\SheetViews\\:\\:\\$worksheet has no typehint specified\\.$#"
3790-
count: 1
3791-
path: src/PhpSpreadsheet/Reader/Xlsx/SheetViews.php
3792-
37933613
-
37943614
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Styles\\:\\:\\$styles has no typehint specified\\.$#"
37953615
count: 1
@@ -3820,11 +3640,6 @@ parameters:
38203640
count: 1
38213641
path: src/PhpSpreadsheet/Reader/Xlsx/Styles.php
38223642

3823-
-
3824-
message: "#^Cannot call method count\\(\\) on SimpleXMLElement\\|null\\.$#"
3825-
count: 1
3826-
path: src/PhpSpreadsheet/Reader/Xlsx/Styles.php
3827-
38283643
-
38293644
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\\\Styles\\:\\:readStyle\\(\\) has parameter \\$style with no typehint specified\\.$#"
38303645
count: 1
@@ -3935,11 +3750,6 @@ parameters:
39353750
count: 1
39363751
path: src/PhpSpreadsheet/ReferenceHelper.php
39373752

3938-
-
3939-
message: "#^Parameter \\#1 \\$pCellRange of method PhpOffice\\\\PhpSpreadsheet\\\\ReferenceHelper\\:\\:updateCellReference\\(\\) expects string, string\\|null given\\.$#"
3940-
count: 1
3941-
path: src/PhpSpreadsheet/ReferenceHelper.php
3942-
39433753
-
39443754
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, string\\|null given\\.$#"
39453755
count: 1
@@ -5645,11 +5455,6 @@ parameters:
56455455
count: 1
56465456
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
56475457

5648-
-
5649-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\:\\:getFreezePane\\(\\) should return string but returns string\\|null\\.$#"
5650-
count: 1
5651-
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
5652-
56535458
-
56545459
message: "#^Parameter \\#1 \\$row of method PhpOffice\\\\PhpSpreadsheet\\\\Collection\\\\Cells\\:\\:removeRow\\(\\) expects string, int given\\.$#"
56555460
count: 2

0 commit comments

Comments
 (0)