Skip to content

Commit 6669588

Browse files
authored
Calculation suppressFormulaErrors - Minor Break and Deprecation (#3092)
Fix #1531. This is a replacement for PR #3081 (see last paragraph below), which I will close. 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. Deprecation - the visibility of the existing property is public, which means it can be changed directly. A new private property is added with a public setter/getter. The new property will be used when the existing property is null (default), which will allow the existing property to be deprecated. Function getFunctions is changed to static - the array which it returns is static. Existing callers using it as non-static will still function correctly. 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 of problems with Calculation.php in phpstan baseline are addressed. PR 3081 ran afoul of something in phpstan. The changes in this ticket are more limited, adding a number of doc blocks but leaving executable code unchanged.
1 parent d27b6a6 commit 6669588

File tree

5 files changed

+158
-191
lines changed

5 files changed

+158
-191
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -25,71 +25,6 @@ parameters:
2525
count: 1
2626
path: src/PhpSpreadsheet/Calculation/Calculation.php
2727

28-
-
29-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:_translateFormulaToEnglish\\(\\) has no return type specified\\.$#"
30-
count: 1
31-
path: src/PhpSpreadsheet/Calculation/Calculation.php
32-
33-
-
34-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:_translateFormulaToEnglish\\(\\) has parameter \\$formula with no type specified\\.$#"
35-
count: 1
36-
path: src/PhpSpreadsheet/Calculation/Calculation.php
37-
38-
-
39-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:_translateFormulaToLocale\\(\\) has no return type specified\\.$#"
40-
count: 1
41-
path: src/PhpSpreadsheet/Calculation/Calculation.php
42-
43-
-
44-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:_translateFormulaToLocale\\(\\) has parameter \\$formula with no type specified\\.$#"
45-
count: 1
46-
path: src/PhpSpreadsheet/Calculation/Calculation.php
47-
48-
-
49-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:dataTestReference\\(\\) has no return type specified\\.$#"
50-
count: 1
51-
path: src/PhpSpreadsheet/Calculation/Calculation.php
52-
53-
-
54-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:dataTestReference\\(\\) has parameter \\$operandData with no type specified\\.$#"
55-
count: 1
56-
path: src/PhpSpreadsheet/Calculation/Calculation.php
57-
58-
-
59-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:getTokensAsString\\(\\) has no return type specified\\.$#"
60-
count: 1
61-
path: src/PhpSpreadsheet/Calculation/Calculation.php
62-
63-
-
64-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:getTokensAsString\\(\\) has parameter \\$tokens with no type specified\\.$#"
65-
count: 1
66-
path: src/PhpSpreadsheet/Calculation/Calculation.php
67-
68-
-
69-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:localeFunc\\(\\) has no return type specified\\.$#"
70-
count: 1
71-
path: src/PhpSpreadsheet/Calculation/Calculation.php
72-
73-
-
74-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:localeFunc\\(\\) has parameter \\$function with no type specified\\.$#"
75-
count: 1
76-
path: src/PhpSpreadsheet/Calculation/Calculation.php
77-
78-
-
79-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:validateBinaryOperand\\(\\) has no return type specified\\.$#"
80-
count: 1
81-
path: src/PhpSpreadsheet/Calculation/Calculation.php
82-
83-
-
84-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:validateBinaryOperand\\(\\) has parameter \\$operand with no type specified\\.$#"
85-
count: 1
86-
path: src/PhpSpreadsheet/Calculation/Calculation.php
87-
88-
-
89-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:validateBinaryOperand\\(\\) has parameter \\$stack with no type specified\\.$#"
90-
count: 1
91-
path: src/PhpSpreadsheet/Calculation/Calculation.php
92-
9328
-
9429
message: "#^Offset 'value' does not exist on array\\|null\\.$#"
9530
count: 5
@@ -105,81 +40,11 @@ parameters:
10540
count: 1
10641
path: src/PhpSpreadsheet/Calculation/Calculation.php
10742

108-
-
109-
message: "#^Parameter \\#1 \\$str of function preg_quote expects string, int\\|string given\\.$#"
110-
count: 1
111-
path: src/PhpSpreadsheet/Calculation/Calculation.php
112-
11343
-
11444
message: "#^Parameter \\#2 \\$worksheet of static method PhpOffice\\\\PhpSpreadsheet\\\\DefinedName\\:\\:resolveName\\(\\) expects PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet, PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null given\\.$#"
11545
count: 1
11646
path: src/PhpSpreadsheet/Calculation/Calculation.php
11747

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

0 commit comments

Comments
 (0)