mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-14 20:16:34 +00:00
Fix Phpstan and Scrutinizer Problems
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheet\Shared\Trend;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
|
||||
|
||||
class Trend
|
||||
{
|
||||
const TREND_LINEAR = 'Linear';
|
||||
@@ -46,7 +48,7 @@ class Trend
|
||||
*/
|
||||
private static array $trendCache = [];
|
||||
|
||||
public static function calculate(string $trendType = self::TREND_BEST_FIT, array $yValues = [], array $xValues = [], bool $const = true): mixed
|
||||
public static function calculate(string $trendType = self::TREND_BEST_FIT, array $yValues = [], array $xValues = [], bool $const = true): BestFit
|
||||
{
|
||||
// Calculate number of points in each dataset
|
||||
$nY = count($yValues);
|
||||
@@ -57,7 +59,7 @@ class Trend
|
||||
$xValues = range(1, $nY);
|
||||
} elseif ($nY !== $nX) {
|
||||
// Ensure both arrays of points are the same size
|
||||
trigger_error('Trend(): Number of elements in coordinate arrays do not match.', E_USER_ERROR);
|
||||
throw new SpreadsheetException('Trend(): Number of elements in coordinate arrays do not match.');
|
||||
}
|
||||
|
||||
$key = md5($trendType . $const . serialize($yValues) . serialize($xValues));
|
||||
@@ -113,7 +115,7 @@ class Trend
|
||||
|
||||
return $bestFit[$bestFitType];
|
||||
default:
|
||||
return false;
|
||||
throw new SpreadsheetException("Unknown trend type $trendType");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,10 +63,26 @@ class BestFitTest extends TestCase
|
||||
|
||||
try {
|
||||
$type = Trend::TREND_BEST_FIT;
|
||||
$result = Trend::calculate($type, $yValues, $xValues);
|
||||
Trend::calculate($type, $yValues, [0, 1, 2]);
|
||||
self::fail('should have failed - mismatched number of elements');
|
||||
} catch (SpreadsheetException $e) {
|
||||
self::assertStringContainsString('Number of elements', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$type = Trend::TREND_BEST_FIT;
|
||||
Trend::calculate($type, $yValues, $xValues);
|
||||
self::fail('should have failed - TREND_BEST_FIT includes polynomials which are not implemented yet');
|
||||
} catch (SpreadsheetException $e) {
|
||||
self::assertStringContainsString('not yet implemented', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$type = 'unknown';
|
||||
Trend::calculate($type, $yValues, $xValues);
|
||||
self::fail('should have failed - invalid trend type');
|
||||
} catch (SpreadsheetException $e) {
|
||||
self::assertStringContainsString('Unknown trend type', $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user