Skip to content

Commit 3dd4862

Browse files
authored
Merge branch 'master' into CalcEngine_Formatted-Currency-Expand-Currency-Range
2 parents 4aaf1f6 + 9e1378d commit 3dd4862

File tree

5 files changed

+51
-188
lines changed

5 files changed

+51
-188
lines changed

phpstan-baseline.neon

-185
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,6 @@ parameters:
2525
count: 1
2626
path: src/PhpSpreadsheet/Calculation/FormulaParser.php
2727

28-
-
29-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Trends\\:\\:GROWTH\\(\\) should return array\\<float\\> but returns array\\<int, array\\<int, array\\<int, mixed\\>\\>\\>\\.$#"
30-
count: 1
31-
path: src/PhpSpreadsheet/Calculation/Statistical/Trends.php
32-
33-
-
34-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Trends\\:\\:TREND\\(\\) should return array\\<float\\> but returns array\\<int, array\\<int, array\\<int, mixed\\>\\>\\>\\.$#"
35-
count: 1
36-
path: src/PhpSpreadsheet/Calculation/Statistical/Trends.php
37-
38-
-
39-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Trends\\:\\:checkTrendArrays\\(\\) has parameter \\$array1 with no type specified\\.$#"
40-
count: 1
41-
path: src/PhpSpreadsheet/Calculation/Statistical/Trends.php
42-
43-
-
44-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Trends\\:\\:checkTrendArrays\\(\\) has parameter \\$array2 with no type specified\\.$#"
45-
count: 1
46-
path: src/PhpSpreadsheet/Calculation/Statistical/Trends.php
47-
4828
-
4929
message: "#^Cannot access offset 1 on array\\|false\\.$#"
5030
count: 1
@@ -220,171 +200,6 @@ parameters:
220200
count: 1
221201
path: src/PhpSpreadsheet/Shared/OLERead.php
222202

223-
-
224-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:calculateGoodnessOfFit\\(\\) has parameter \\$const with no type specified\\.$#"
225-
count: 1
226-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
227-
228-
-
229-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:calculateGoodnessOfFit\\(\\) has parameter \\$meanX with no type specified\\.$#"
230-
count: 1
231-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
232-
233-
-
234-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:calculateGoodnessOfFit\\(\\) has parameter \\$meanY with no type specified\\.$#"
235-
count: 1
236-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
237-
238-
-
239-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:calculateGoodnessOfFit\\(\\) has parameter \\$sumX with no type specified\\.$#"
240-
count: 1
241-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
242-
243-
-
244-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:calculateGoodnessOfFit\\(\\) has parameter \\$sumX2 with no type specified\\.$#"
245-
count: 1
246-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
247-
248-
-
249-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:calculateGoodnessOfFit\\(\\) has parameter \\$sumXY with no type specified\\.$#"
250-
count: 1
251-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
252-
253-
-
254-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:calculateGoodnessOfFit\\(\\) has parameter \\$sumY with no type specified\\.$#"
255-
count: 1
256-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
257-
258-
-
259-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:calculateGoodnessOfFit\\(\\) has parameter \\$sumY2 with no type specified\\.$#"
260-
count: 1
261-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
262-
263-
-
264-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:getBestFitType\\(\\) has no return type specified\\.$#"
265-
count: 1
266-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
267-
268-
-
269-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:getError\\(\\) has no return type specified\\.$#"
270-
count: 1
271-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
272-
273-
-
274-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:sumSquares\\(\\) has no return type specified\\.$#"
275-
count: 1
276-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
277-
278-
-
279-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:\\$DFResiduals has no type specified\\.$#"
280-
count: 1
281-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
282-
283-
-
284-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:\\$SSRegression has no type specified\\.$#"
285-
count: 1
286-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
287-
288-
-
289-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:\\$SSResiduals has no type specified\\.$#"
290-
count: 1
291-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
292-
293-
-
294-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:\\$correlation has no type specified\\.$#"
295-
count: 1
296-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
297-
298-
-
299-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:\\$covariance has no type specified\\.$#"
300-
count: 1
301-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
302-
303-
-
304-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:\\$f has no type specified\\.$#"
305-
count: 1
306-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
307-
308-
-
309-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:\\$goodnessOfFit has no type specified\\.$#"
310-
count: 1
311-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
312-
313-
-
314-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:\\$intersect has no type specified\\.$#"
315-
count: 1
316-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
317-
318-
-
319-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:\\$intersectSE has no type specified\\.$#"
320-
count: 1
321-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
322-
323-
-
324-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:\\$slope has no type specified\\.$#"
325-
count: 1
326-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
327-
328-
-
329-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:\\$slopeSE has no type specified\\.$#"
330-
count: 1
331-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
332-
333-
-
334-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:\\$stdevOfResiduals has no type specified\\.$#"
335-
count: 1
336-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
337-
338-
-
339-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:\\$xOffset has no type specified\\.$#"
340-
count: 1
341-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
342-
343-
-
344-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:\\$yOffset has no type specified\\.$#"
345-
count: 1
346-
path: src/PhpSpreadsheet/Shared/Trend/BestFit.php
347-
348-
-
349-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\PolynomialBestFit\\:\\:getCoefficients\\(\\) has no return type specified\\.$#"
350-
count: 1
351-
path: src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php
352-
353-
-
354-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\PolynomialBestFit\\:\\:getCoefficients\\(\\) has parameter \\$dp with no type specified\\.$#"
355-
count: 1
356-
path: src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php
357-
358-
-
359-
message: "#^Call to an undefined method object\\:\\:getGoodnessOfFit\\(\\)\\.$#"
360-
count: 1
361-
path: src/PhpSpreadsheet/Shared/Trend/Trend.php
362-
363-
-
364-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\Trend\\:\\:calculate\\(\\) has no return type specified\\.$#"
365-
count: 1
366-
path: src/PhpSpreadsheet/Shared/Trend/Trend.php
367-
368-
-
369-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\Trend\\:\\:calculate\\(\\) has parameter \\$const with no type specified\\.$#"
370-
count: 1
371-
path: src/PhpSpreadsheet/Shared/Trend/Trend.php
372-
373-
-
374-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\Trend\\:\\:calculate\\(\\) has parameter \\$trendType with no type specified\\.$#"
375-
count: 1
376-
path: src/PhpSpreadsheet/Shared/Trend/Trend.php
377-
378-
-
379-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\Trend\\:\\:calculate\\(\\) has parameter \\$xValues with no type specified\\.$#"
380-
count: 1
381-
path: src/PhpSpreadsheet/Shared/Trend/Trend.php
382-
383-
-
384-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\Trend\\:\\:calculate\\(\\) has parameter \\$yValues with no type specified\\.$#"
385-
count: 1
386-
path: src/PhpSpreadsheet/Shared/Trend/Trend.php
387-
388203
-
389204
message: "#^Cannot access offset 'comp' on array\\|false\\.$#"
390205
count: 1

src/PhpSpreadsheet/Calculation/Statistical/Trends.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ private static function filterTrendValues(array &$array1, array &$array2): void
2121
}
2222
}
2323

24+
/**
25+
* @param mixed $array1 should be array, but scalar is made into one
26+
* @param mixed $array2 should be array, but scalar is made into one
27+
*/
2428
private static function checkTrendArrays(&$array1, &$array2): void
2529
{
2630
if (!is_array($array1)) {
@@ -168,7 +172,7 @@ public static function GROWTH($yValues, $xValues = [], $newValues = [], $const =
168172
$returnArray[0][] = [$bestFitExponential->getValueOfYForX($xValue)];
169173
}
170174

171-
return $returnArray;
175+
return $returnArray; //* @phpstan-ignore-line
172176
}
173177

174178
/**
@@ -425,6 +429,6 @@ public static function TREND($yValues, $xValues = [], $newValues = [], $const =
425429
$returnArray[0][] = [$bestFitLinear->getValueOfYForX($xValue)];
426430
}
427431

428-
return $returnArray;
432+
return $returnArray; //* @phpstan-ignore-line
429433
}
430434
}

src/PhpSpreadsheet/Shared/Trend/BestFit.php

+27
Original file line numberDiff line numberDiff line change
@@ -53,39 +53,55 @@ abstract class BestFit
5353
*/
5454
protected $yBestFitValues = [];
5555

56+
/** @var float */
5657
protected $goodnessOfFit = 1;
5758

59+
/** @var float */
5860
protected $stdevOfResiduals = 0;
5961

62+
/** @var float */
6063
protected $covariance = 0;
6164

65+
/** @var float */
6266
protected $correlation = 0;
6367

68+
/** @var float */
6469
protected $SSRegression = 0;
6570

71+
/** @var float */
6672
protected $SSResiduals = 0;
6773

74+
/** @var float */
6875
protected $DFResiduals = 0;
6976

77+
/** @var float */
7078
protected $f = 0;
7179

80+
/** @var float */
7281
protected $slope = 0;
7382

83+
/** @var float */
7484
protected $slopeSE = 0;
7585

86+
/** @var float */
7687
protected $intersect = 0;
7788

89+
/** @var float */
7890
protected $intersectSE = 0;
7991

92+
/** @var float */
8093
protected $xOffset = 0;
8194

95+
/** @var float */
8296
protected $yOffset = 0;
8397

98+
/** @return bool */
8499
public function getError()
85100
{
86101
return $this->error;
87102
}
88103

104+
/** @return string */
89105
public function getBestFitType()
90106
{
91107
return $this->bestFitType;
@@ -344,6 +360,16 @@ private static function scrutinizerLooseCompare($x, $y): bool
344360
return $x == $y;
345361
}
346362

363+
/**
364+
* @param float $sumX
365+
* @param float $sumY
366+
* @param float $sumX2
367+
* @param float $sumY2
368+
* @param float $sumXY
369+
* @param float $meanX
370+
* @param float $meanY
371+
* @param bool|int $const
372+
*/
347373
protected function calculateGoodnessOfFit($sumX, $sumY, $sumX2, $sumY2, $sumXY, $meanX, $meanY, $const): void
348374
{
349375
$SSres = $SScov = $SStot = $SSsex = 0.0;
@@ -399,6 +425,7 @@ protected function calculateGoodnessOfFit($sumX, $sumY, $sumX2, $sumY2, $sumXY,
399425
}
400426
}
401427

428+
/** @return float|int */
402429
private function sumSquares(array $values)
403430
{
404431
return array_sum(

src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php

+8
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public function getSlope($dp = 0)
108108
if ($dp != 0) {
109109
$coefficients = [];
110110
// Scrutinizer is correct - $this->slope is float, not array.
111+
//* @phpstan-ignore-next-line
111112
foreach ($this->slope as $coefficient) {
112113
$coefficients[] = round($coefficient, $dp);
113114
}
@@ -119,6 +120,11 @@ public function getSlope($dp = 0)
119120
return $this->slope;
120121
}
121122

123+
/**
124+
* @param int $dp
125+
*
126+
* @return array
127+
*/
122128
public function getCoefficients($dp = 0)
123129
{
124130
// Phpstan and Scrutinizer are both correct - getSlope returns float, not array.
@@ -176,6 +182,8 @@ private function polynomialRegression($order, $yValues, $xValues): void
176182
}
177183

178184
$this->intersect = array_shift($coefficients);
185+
// Phpstan (and maybe Scrutinizer) are correct
186+
//* @phpstan-ignore-next-line
179187
$this->slope = $coefficients;
180188

181189
$this->calculateGoodnessOfFit($x_sum, $y_sum, $xx_sum, $yy_sum, $xy_sum, 0, 0, 0);

src/PhpSpreadsheet/Shared/Trend/Trend.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ class Trend
4848
*/
4949
private static $trendCache = [];
5050

51+
/**
52+
* @param string $trendType
53+
* @param array $yValues
54+
* @param array $xValues
55+
* @param bool $const
56+
*
57+
* @return mixed
58+
*/
5159
public static function calculate($trendType = self::TREND_BEST_FIT, $yValues = [], $xValues = [], $const = true)
5260
{
5361
// Calculate number of points in each dataset
@@ -72,7 +80,6 @@ public static function calculate($trendType = self::TREND_BEST_FIT, $yValues = [
7280
case self::TREND_POWER:
7381
if (!isset(self::$trendCache[$key])) {
7482
$className = '\PhpOffice\PhpSpreadsheet\Shared\Trend\\' . $trendType . 'BestFit';
75-
// @phpstan-ignore-next-line
7683
self::$trendCache[$key] = new $className($yValues, $xValues, $const);
7784
}
7885

@@ -96,7 +103,9 @@ public static function calculate($trendType = self::TREND_BEST_FIT, $yValues = [
96103
$bestFitValue = [];
97104
foreach (self::$trendTypes as $trendMethod) {
98105
$className = '\PhpOffice\PhpSpreadsheet\Shared\Trend\\' . $trendType . 'BestFit';
106+
//* @phpstan-ignore-next-line
99107
$bestFit[$trendMethod] = new $className($yValues, $xValues, $const);
108+
//* @phpstan-ignore-next-line
100109
$bestFitValue[$trendMethod] = $bestFit[$trendMethod]->getGoodnessOfFit();
101110
}
102111
if ($trendType != self::TREND_BEST_FIT_NO_POLY) {

0 commit comments

Comments
 (0)