Skip to content

Commit e59e366

Browse files
committed
Calculation suppressFormulaErrors - Minor Breaks
Fix PHPOffice#1531. Calculation has a property `suppressFormulaErrors`, which really doesn't work as one might expect. If a calculation throws an exception, the setting of this property might prevent the Exception from being thrown, but it will still trigger an Error. I do not think this makes sense, and will change it so the calculation will return `false`, which is part of the original design but which would essentially never happen. This allows the user to save a corrupt spreadsheet, but this was already possible through the use of `setPreCalculateFormulas(false)` on the Writer, so this doesn't really open any new exposures. It nevertheless might be considered a breaking change because of the difference in behavior. Another break - the visibility of the property is changed from public to private, and a public setter/getter is added. Although I am enabling this ability, I don't necessarily think it's a good idea to make use of it. See the original issue for a discussion of why. It is not mentioned in the official documentation, and I will not be adding documentation for it. The originator discovered it by reading the code, and I think that is sufficient for what will often be an ill-advised choice. Many of the large number (unfortunately not quite all) of problems with Calculation.php in phpstan baseline are addressed. Of note are that private arrays `phpSpreadsheetFunctions`, `controlFunctions`, `comparisonOperators`, and `operatorPrecedence` are changed from static to const.
1 parent 53e0828 commit e59e366

File tree

5 files changed

+151
-266
lines changed

5 files changed

+151
-266
lines changed

phpstan-baseline.neon

-170
Original file line numberDiff line numberDiff line change
@@ -5,186 +5,16 @@ parameters:
55
count: 3
66
path: src/PhpSpreadsheet/Calculation/Calculation.php
77

8-
-
9-
message: "#^Cannot call method attach\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell\\|null\\.$#"
10-
count: 1
11-
path: src/PhpSpreadsheet/Calculation/Calculation.php
12-
13-
-
14-
message: "#^Cannot call method cellExists\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
15-
count: 4
16-
path: src/PhpSpreadsheet/Calculation/Calculation.php
17-
18-
-
19-
message: "#^Cannot call method getCell\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
20-
count: 6
21-
path: src/PhpSpreadsheet/Calculation/Calculation.php
22-
23-
-
24-
message: "#^Cannot call method getHighestColumn\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
25-
count: 1
26-
path: src/PhpSpreadsheet/Calculation/Calculation.php
27-
28-
-
29-
message: "#^Cannot call method getHighestRow\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
30-
count: 1
31-
path: src/PhpSpreadsheet/Calculation/Calculation.php
32-
33-
-
34-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:_translateFormulaToEnglish\\(\\) has no return type specified\\.$#"
35-
count: 1
36-
path: src/PhpSpreadsheet/Calculation/Calculation.php
37-
38-
-
39-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:_translateFormulaToEnglish\\(\\) has parameter \\$formula with no type specified\\.$#"
40-
count: 1
41-
path: src/PhpSpreadsheet/Calculation/Calculation.php
42-
43-
-
44-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:_translateFormulaToLocale\\(\\) has no return type specified\\.$#"
45-
count: 1
46-
path: src/PhpSpreadsheet/Calculation/Calculation.php
47-
48-
-
49-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:_translateFormulaToLocale\\(\\) has parameter \\$formula with no type specified\\.$#"
50-
count: 1
51-
path: src/PhpSpreadsheet/Calculation/Calculation.php
52-
53-
-
54-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:dataTestReference\\(\\) has no return type specified\\.$#"
55-
count: 1
56-
path: src/PhpSpreadsheet/Calculation/Calculation.php
57-
58-
-
59-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:dataTestReference\\(\\) has parameter \\$operandData with no type specified\\.$#"
60-
count: 1
61-
path: src/PhpSpreadsheet/Calculation/Calculation.php
62-
63-
-
64-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:getTokensAsString\\(\\) has no return type specified\\.$#"
65-
count: 1
66-
path: src/PhpSpreadsheet/Calculation/Calculation.php
67-
68-
-
69-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:getTokensAsString\\(\\) has parameter \\$tokens with no type specified\\.$#"
70-
count: 1
71-
path: src/PhpSpreadsheet/Calculation/Calculation.php
72-
73-
-
74-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:localeFunc\\(\\) has no return type specified\\.$#"
75-
count: 1
76-
path: src/PhpSpreadsheet/Calculation/Calculation.php
77-
78-
-
79-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:localeFunc\\(\\) has parameter \\$function with no type specified\\.$#"
80-
count: 1
81-
path: src/PhpSpreadsheet/Calculation/Calculation.php
82-
83-
-
84-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:validateBinaryOperand\\(\\) has no return type specified\\.$#"
85-
count: 1
86-
path: src/PhpSpreadsheet/Calculation/Calculation.php
87-
88-
-
89-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:validateBinaryOperand\\(\\) has parameter \\$operand with no type specified\\.$#"
90-
count: 1
91-
path: src/PhpSpreadsheet/Calculation/Calculation.php
92-
93-
-
94-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:validateBinaryOperand\\(\\) has parameter \\$stack with no type specified\\.$#"
95-
count: 1
96-
path: src/PhpSpreadsheet/Calculation/Calculation.php
97-
988
-
999
message: "#^Offset 'value' does not exist on array\\|null\\.$#"
10010
count: 5
10111
path: src/PhpSpreadsheet/Calculation/Calculation.php
10212

103-
-
104-
message: "#^Parameter \\#1 \\$haystack of function stripos expects string, float\\|int\\|string given\\.$#"
105-
count: 1
106-
path: src/PhpSpreadsheet/Calculation/Calculation.php
107-
108-
-
109-
message: "#^Parameter \\#1 \\$haystack of function strpos expects string, float\\|int\\|string given\\.$#"
110-
count: 1
111-
path: src/PhpSpreadsheet/Calculation/Calculation.php
112-
113-
-
114-
message: "#^Parameter \\#1 \\$str of function preg_quote expects string, int\\|string given\\.$#"
115-
count: 1
116-
path: src/PhpSpreadsheet/Calculation/Calculation.php
117-
11813
-
11914
message: "#^Parameter \\#2 \\$worksheet of static method PhpOffice\\\\PhpSpreadsheet\\\\DefinedName\\:\\:resolveName\\(\\) expects PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet, PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null given\\.$#"
12015
count: 1
12116
path: src/PhpSpreadsheet/Calculation/Calculation.php
12217

123-
-
124-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$cellStack has no type specified\\.$#"
125-
count: 1
126-
path: src/PhpSpreadsheet/Calculation/Calculation.php
127-
128-
-
129-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$comparisonOperators has no type specified\\.$#"
130-
count: 1
131-
path: src/PhpSpreadsheet/Calculation/Calculation.php
132-
133-
-
134-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$controlFunctions has no type specified\\.$#"
135-
count: 1
136-
path: src/PhpSpreadsheet/Calculation/Calculation.php
137-
138-
-
139-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$cyclicFormulaCell has no type specified\\.$#"
140-
count: 1
141-
path: src/PhpSpreadsheet/Calculation/Calculation.php
142-
143-
-
144-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$functionReplaceFromExcel has no type specified\\.$#"
145-
count: 1
146-
path: src/PhpSpreadsheet/Calculation/Calculation.php
147-
148-
-
149-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$functionReplaceFromLocale has no type specified\\.$#"
150-
count: 1
151-
path: src/PhpSpreadsheet/Calculation/Calculation.php
152-
153-
-
154-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$functionReplaceToExcel has no type specified\\.$#"
155-
count: 1
156-
path: src/PhpSpreadsheet/Calculation/Calculation.php
157-
158-
-
159-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$functionReplaceToLocale has no type specified\\.$#"
160-
count: 1
161-
path: src/PhpSpreadsheet/Calculation/Calculation.php
162-
163-
-
164-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$localeFunctions has no type specified\\.$#"
165-
count: 1
166-
path: src/PhpSpreadsheet/Calculation/Calculation.php
167-
168-
-
169-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$operatorAssociativity has no type specified\\.$#"
170-
count: 1
171-
path: src/PhpSpreadsheet/Calculation/Calculation.php
172-
173-
-
174-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$operatorPrecedence has no type specified\\.$#"
175-
count: 1
176-
path: src/PhpSpreadsheet/Calculation/Calculation.php
177-
178-
-
179-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$phpSpreadsheetFunctions has no type specified\\.$#"
180-
count: 1
181-
path: src/PhpSpreadsheet/Calculation/Calculation.php
182-
183-
-
184-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$returnArrayAsType has no type specified\\.$#"
185-
count: 1
186-
path: src/PhpSpreadsheet/Calculation/Calculation.php
187-
18818
-
18919
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$spreadsheet \\(PhpOffice\\\\PhpSpreadsheet\\\\Spreadsheet\\) does not accept PhpOffice\\\\PhpSpreadsheet\\\\Spreadsheet\\|null\\.$#"
19020
count: 1

0 commit comments

Comments
 (0)