Skip to content

Commit 33d3442

Browse files
author
MarkBaker
committed
Merge branch '2.0-Development' into CalculationEngine-Array-Formulae-Initial-Work
# Conflicts: # phpstan-baseline.neon # src/PhpSpreadsheet/Calculation/Calculation.php # src/PhpSpreadsheet/Calculation/Functions.php # src/PhpSpreadsheet/Calculation/MathTrig.php
2 parents e1e5888 + 78ea02a commit 33d3442

File tree

375 files changed

+754
-10541
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

375 files changed

+754
-10541
lines changed

docs/topics/recipes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ internal English coding.
349349

350350
```php
351351
$formula = $spreadsheet->getActiveSheet()->getCell('B8')->getValue();
352-
$translatedFormula = \PhpOffice\PhpSpreadsheet\Calculation\Calculation::getInstance()->_translateFormulaToLocale($formula);
352+
$translatedFormula = \PhpOffice\PhpSpreadsheet\Calculation\Calculation::getInstance()->translateFormulaToLocale($formula);
353353
```
354354

355355
You can also create a formula using the function names and argument

phpstan-baseline.neon

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -180,51 +180,6 @@ parameters:
180180
count: 1
181181
path: src/PhpSpreadsheet/Calculation/Calculation.php
182182

183-
-
184-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Database\\:\\:DMAX\\(\\) should return float but returns float\\|string\\|null\\.$#"
185-
count: 1
186-
path: src/PhpSpreadsheet/Calculation/Database.php
187-
188-
-
189-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Database\\:\\:DMIN\\(\\) should return float but returns float\\|string\\|null\\.$#"
190-
count: 1
191-
path: src/PhpSpreadsheet/Calculation/Database.php
192-
193-
-
194-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Database\\:\\:DPRODUCT\\(\\) should return float\\|string but returns float\\|string\\|null\\.$#"
195-
count: 1
196-
path: src/PhpSpreadsheet/Calculation/Database.php
197-
198-
-
199-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Database\\:\\:DSTDEV\\(\\) should return float\\|string but returns float\\|string\\|null\\.$#"
200-
count: 1
201-
path: src/PhpSpreadsheet/Calculation/Database.php
202-
203-
-
204-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Database\\:\\:DSTDEVP\\(\\) should return float\\|string but returns float\\|string\\|null\\.$#"
205-
count: 1
206-
path: src/PhpSpreadsheet/Calculation/Database.php
207-
208-
-
209-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Database\\:\\:DSUM\\(\\) should return float\\|string but returns float\\|string\\|null\\.$#"
210-
count: 1
211-
path: src/PhpSpreadsheet/Calculation/Database.php
212-
213-
-
214-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Database\\:\\:DVAR\\(\\) should return float\\|string but returns float\\|string\\|null\\.$#"
215-
count: 1
216-
path: src/PhpSpreadsheet/Calculation/Database.php
217-
218-
-
219-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Database\\:\\:DVARP\\(\\) should return float\\|string but returns float\\|string\\|null\\.$#"
220-
count: 1
221-
path: src/PhpSpreadsheet/Calculation/Database.php
222-
223-
-
224-
message: "#^Parameter \\#2 \\$field of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Database\\\\DCountA\\:\\:evaluate\\(\\) expects int\\|string, int\\|string\\|null given\\.$#"
225-
count: 1
226-
path: src/PhpSpreadsheet/Calculation/Database.php
227-
228183
-
229184
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Database\\\\DatabaseAbstract\\:\\:buildCondition\\(\\) has parameter \\$criterion with no type specified\\.$#"
230185
count: 1
@@ -325,21 +280,6 @@ parameters:
325280
count: 1
326281
path: src/PhpSpreadsheet/Calculation/Engineering/ErfC.php
327282

328-
-
329-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\:\\:ISPMT\\(\\) has no return type specified\\.$#"
330-
count: 1
331-
path: src/PhpSpreadsheet/Calculation/Financial.php
332-
333-
-
334-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\:\\:ISPMT\\(\\) has parameter \\$args with no type specified\\.$#"
335-
count: 1
336-
path: src/PhpSpreadsheet/Calculation/Financial.php
337-
338-
-
339-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\:\\:NPV\\(\\) has parameter \\$args with no type specified\\.$#"
340-
count: 1
341-
path: src/PhpSpreadsheet/Calculation/Financial.php
342-
343283
-
344284
message: "#^Parameter \\#1 \\$year of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Helpers\\:\\:isLeapYear\\(\\) expects int\\|string, array\\|int\\|string given\\.$#"
345285
count: 1
@@ -575,16 +515,6 @@ parameters:
575515
count: 3
576516
path: src/PhpSpreadsheet/Calculation/Logical/Operations.php
577517

578-
-
579-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\LookupRef\\:\\:CHOOSE\\(\\) has parameter \\$chooseArgs with no type specified\\.$#"
580-
count: 1
581-
path: src/PhpSpreadsheet/Calculation/LookupRef.php
582-
583-
-
584-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\LookupRef\\:\\:OFFSET\\(\\) should return array\\|string but returns array\\|int\\|string\\.$#"
585-
count: 1
586-
path: src/PhpSpreadsheet/Calculation/LookupRef.php
587-
588518
-
589519
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\LookupRef\\\\Address\\:\\:sheetName\\(\\) has no return type specified\\.$#"
590520
count: 1
@@ -775,16 +705,6 @@ parameters:
775705
count: 1
776706
path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
777707

778-
-
779-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\:\\:MAXIFS\\(\\) should return float but returns float\\|string\\|null\\.$#"
780-
count: 1
781-
path: src/PhpSpreadsheet/Calculation/Statistical.php
782-
783-
-
784-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\:\\:MINIFS\\(\\) should return float but returns float\\|string\\|null\\.$#"
785-
count: 1
786-
path: src/PhpSpreadsheet/Calculation/Statistical.php
787-
788708
-
789709
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Averages\\:\\:filterArguments\\(\\) has no return type specified\\.$#"
790710
count: 1
@@ -1065,11 +985,6 @@ parameters:
1065985
count: 1
1066986
path: src/PhpSpreadsheet/Calculation/Statistical/VarianceBase.php
1067987

1068-
-
1069-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\TextData\\:\\:CONCATENATE\\(\\) has parameter \\$args with no type specified\\.$#"
1070-
count: 1
1071-
path: src/PhpSpreadsheet/Calculation/TextData.php
1072-
1073988
-
1074989
message: "#^Variable \\$value on left side of \\?\\? always exists and is not nullable\\.$#"
1075990
count: 4

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class Calculation
295295
],
296296
'ARABIC' => [
297297
'category' => Category::CATEGORY_MATH_AND_TRIG,
298-
'functionCall' => [MathTrig\Arabic::class, 'evaluate'],
298+
'functionCall' => [MathTrig\Arabic::class, 'toRoman'],
299299
'argumentCount' => '1',
300300
],
301301
'AREAS' => [
@@ -2169,7 +2169,7 @@ class Calculation
21692169
],
21702170
'ROMAN' => [
21712171
'category' => Category::CATEGORY_MATH_AND_TRIG,
2172-
'functionCall' => [MathTrig\Roman::class, 'evaluate'],
2172+
'functionCall' => [MathTrig\Roman::class, 'toArabic'],
21732173
'argumentCount' => '1,2',
21742174
],
21752175
'ROUND' => [
@@ -2844,7 +2844,7 @@ class Calculation
28442844
],
28452845
'NAME.ERROR' => [
28462846
'argumentCount' => '*',
2847-
'functionCall' => [Functions::class, 'NAME'],
2847+
'functionCall' => [Information\ExcelError::class, 'NAME'],
28482848
],
28492849
'WILDCARDMATCH' => [
28502850
'argumentCount' => '2',
@@ -3258,7 +3258,7 @@ private static function translateFormula(array $from, array $to, string $formula
32583258

32593259
private static $functionReplaceToLocale;
32603260

3261-
public function _translateFormulaToLocale(string $formula): string
3261+
public function translateFormulaToLocale(string $formula): string
32623262
{
32633263
// Build list of function names and constants for translation
32643264
if (self::$functionReplaceFromExcel === null) {
@@ -3294,7 +3294,7 @@ public function _translateFormulaToLocale(string $formula): string
32943294

32953295
private static $functionReplaceToExcel;
32963296

3297-
public function _translateFormulaToEnglish(string $formula): string
3297+
public function translateFormulaToEnglish(string $formula): string
32983298
{
32993299
if (self::$functionReplaceFromLocale === null) {
33003300
self::$functionReplaceFromLocale = [];
@@ -3432,8 +3432,7 @@ public function calculateCellValue(?Cell $cell = null, bool $asArray = false, bo
34323432
];
34333433

34343434
try {
3435-
$result = self::unwrapResult($this->_calculateFormulaValue($cell->getValue(), $cell->getCoordinate(), $cell));
3436-
3435+
$result = self::unwrapResult($this->calculateFormulaValue($cell->getValue(), $cell->getCoordinate(), $cell));
34373436
$cellAddress = array_pop($this->cellStack);
34383437
$this->spreadsheet->getSheetByName($cellAddress['sheet'])->getCell($cellAddress['cell']);
34393438
} catch (\Exception $e) {
@@ -3530,7 +3529,7 @@ public function calculateFormula($formula, $cellID = null, ?Cell $cell = null)
35303529

35313530
// Execute the calculation
35323531
try {
3533-
$result = self::unwrapResult($this->_calculateFormulaValue($formula, $cellID, $cell));
3532+
$result = self::unwrapResult($this->calculateFormulaValue($formula, $cellID, $cell));
35343533
} catch (\Exception $e) {
35353534
throw new Exception($e->getMessage());
35363535
}
@@ -3583,7 +3582,7 @@ public function saveValueToCache($cellReference, $cellValue): void
35833582
*
35843583
* @return mixed
35853584
*/
3586-
public function _calculateFormulaValue($formula, $cellID = null, ?Cell $cell = null)
3585+
public function calculateFormulaValue($formula, $cellID = null, ?Cell $cell = null)
35873586
{
35883587
$cellValue = null;
35893588

@@ -4743,7 +4742,7 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $cell = null)
47434742
}
47444743
if (count(Functions::flattenArray($cellIntersect)) === 0) {
47454744
$this->debugLog->writeDebugLog('Evaluation Result is %s', $this->showTypeDetails($cellIntersect));
4746-
$stack->push('Error', Functions::null(), null);
4745+
$stack->push('Error', ExcelError::null(), null);
47474746
} else {
47484747
$cellRef = Coordinate::stringFromColumnIndex(min($oCol) + 1) . min($oRow) . ':' .
47494748
Coordinate::stringFromColumnIndex(max($oCol) + 1) . max($oRow);
@@ -5526,7 +5525,7 @@ private function evaluateDefinedName(Cell $cell, DefinedName $namedRange, Worksh
55265525
$recursiveCalculator = new self($this->spreadsheet);
55275526
$recursiveCalculator->getDebugLog()->setWriteDebugLog($this->getDebugLog()->getWriteDebugLog());
55285527
$recursiveCalculator->getDebugLog()->setEchoDebugLog($this->getDebugLog()->getEchoDebugLog());
5529-
$result = $recursiveCalculator->_calculateFormulaValue($definedNameValue, $recursiveCalculationCellAddress, $recursiveCalculationCell);
5528+
$result = $recursiveCalculator->calculateFormulaValue($definedNameValue, $recursiveCalculationCellAddress, $recursiveCalculationCell);
55305529

55315530
if ($this->getDebugLog()->getWriteDebugLog()) {
55325531
$this->debugLog->mergeDebugLog(array_slice($recursiveCalculator->getDebugLog()->getLog(), 3));

0 commit comments

Comments
 (0)