← All changes
|
libraries/vendor/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php
+6
-15
3.3.1
→
3.4
View file →
| @@ -44,11 +44,9 @@ | ||
| 44 | 44 | public function getValueOfYForX(float $xValue): float |
| 45 | 45 | { |
| 46 | 46 | $retVal = $this->getIntersect(); |
| 47 | 47 | $slope = $this->getSlope(); |
| 48 | - // Phpstan and Scrutinizer are both correct - getSlope returns float, not array. | |
| 49 | - // @phpstan-ignore-next-line | |
| 50 | - foreach ($slope as $key => $value) { | |
| 48 | + foreach ($slope as $key => $value) { //* @phpstan-ignore foreach.nonIterable (this whole class is a mess) | |
| 51 | 49 | /** @var float $value */ |
| 52 | 50 | if ($value != 0.0) { |
| 53 | 51 | /** @var int $key */ |
| 54 | 52 | $retVal += $value * $xValue ** ($key + 1); |
| @@ -81,10 +79,9 @@ | ||
| 81 | 79 | $intersect = $this->getIntersect($dp); |
| 82 | 80 | |
| 83 | 81 | $equation = 'Y = ' . $intersect; |
| 84 | 82 | // Phpstan and Scrutinizer are both correct - getSlope returns float, not array. |
| 85 | - // @phpstan-ignore-next-line | |
| 86 | - foreach ($slope as $key => $value) { | |
| 83 | + foreach ($slope as $key => $value) { //* @phpstan-ignore foreach.nonIterable (this whole class is a mess) | |
| 87 | 84 | /** @var float|int $value */ |
| 88 | 85 | if ($value != 0.0) { |
| 89 | 86 | $equation .= ' + ' . $value . ' * X'; |
| 90 | 87 | /** @var int $key */ |
| @@ -105,16 +102,14 @@ | ||
| 105 | 102 | public function getSlope(int $dp = 0): float |
| 106 | 103 | { |
| 107 | 104 | if ($dp != 0) { |
| 108 | 105 | $coefficients = []; |
| 109 | - //* @phpstan-ignore-next-line | |
| 110 | - foreach ($this->slope as $coefficient) { | |
| 106 | + foreach ($this->slope as $coefficient) { //* @phpstan-ignore foreach.nonIterable (this whole class is a mess) | |
| 111 | 107 | /** @var float|int $coefficient */ |
| 112 | 108 | $coefficients[] = round($coefficient, $dp); |
| 113 | 109 | } |
| 114 | 110 | |
| 115 | - // @phpstan-ignore-next-line | |
| 116 | - return $coefficients; | |
| 111 | + return $coefficients; //* @phpstan-ignore return.type (this whole class is a mess) | |
| 117 | 112 | } |
| 118 | 113 | |
| 119 | 114 | return $this->slope; |
| 120 | 115 | } |
| @@ -121,11 +116,9 @@ | ||
| 121 | 116 | |
| 122 | 117 | /** @return array<float|int> */ |
| 123 | 118 | public function getCoefficients(int $dp = 0): array |
| 124 | 119 | { |
| 125 | - // Phpstan and Scrutinizer are both correct - getSlope returns float, not array. | |
| 126 | - // @phpstan-ignore-next-line | |
| 127 | - return array_merge([$this->getIntersect($dp)], $this->getSlope($dp)); | |
| 120 | + return array_merge([$this->getIntersect($dp)], $this->getSlope($dp)); //* @phpstan-ignore return.type (this whole class is a mess), argument.type (ditto) | |
| 128 | 121 | } |
| 129 | 122 | |
| 130 | 123 | /** |
| 131 | 124 | * Execute the regression and calculate the goodness of fit for a set of X and Y data values. |
| @@ -178,11 +171,9 @@ | ||
| 178 | 171 | $coefficients[] = $r; |
| 179 | 172 | } |
| 180 | 173 | |
| 181 | 174 | $this->intersect = (float) array_shift($coefficients); |
| 182 | - // Phpstan is correct | |
| 183 | - //* @phpstan-ignore-next-line | |
| 184 | - $this->slope = $coefficients; | |
| 175 | + $this->slope = $coefficients; //* @phpstan-ignore assign.propertyType (this whole class is a mess) | |
| 185 | 176 | |
| 186 | 177 | $this->calculateGoodnessOfFit($x_sum, $y_sum, $xx_sum, $yy_sum, $xy_sum, 0, 0, 0); |
| 187 | 178 | foreach ($this->xValues as $xKey => $xValue) { |
| 188 | 179 | $this->yBestFitValues[$xKey] = $this->getValueOfYForX($xValue); |