mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-25 10:28:15 +00:00
4adafecea9
* Eliminate Shared\JAMA The code under `Shared\JAMA` is called from exactly 3 places in Calculation, and exactly 1 other place (see next paragraph). These places are inadequately covered in the test suite, so it is not clear that the existing code works. In addition, see PR #2964 for commentary decrying the continued used of JAMA. I will also note that it has a pitiful 8.20% coverage in the test suite. There seems to already be a perfectly adequate equivalent in Calculation for those parts of JAMA which are used (e.g. we don't use any decompositions, so the fact that no decomposition code is present in Calculation is not a problem). This PR replaces the uses of JAMA within Calculation with `checkMatrixOperands`, and deletes Shared/JAMA entirely (which, among other thing, makes many Phpstan reported problems go away). The test suite is enhanced to ensure coverage of all the changed statements. A side benefit of deleting Shared/Jama is that the only function which PhpSpreadsheet has added to the global namespace (hypo in Maths.php) goes away. There is one additional use in Shared/Trend/PolynomialBestFit. That use is best replaced with Matrix/Matrix, which is already a requirement for PhpSpreadsheet. PolynomialBestFit has zero test coverage, and I didn't add any for this change. There seem to be existing errors which both Phpstan and Scrutinizer complain about, and I am quite convinced that they are not false positives. Fixing those problems will be a project for another day. Calculation has many calls to `Information\ErrorValue` and `Information\ExcelError`. It is inconsistent in how it does so - most invoke `Information\E...` but a small number take advantage of additional `use` statements to just invoke `E...`. I have made the usage consistent by changing the small number to act like the majority and eliminating the `use` statements. Some of the test cases exposed the fact that MAX, MAXA, MIN, and MINA do not properly handle error strings in their input. For example, if cell A1 contains 2, and A2 contains `=5/0`, `=MAX(A1, A2)` should return `#DIV/0!`. They are changed to handle them properly. `Shared\JAMA` was normally omitted from code coverage. Since it is being deleted, there is no longer a reason to explicitly exclude it. `Writer\PDF` was also on the exclude list, probably for historical reasons, but there is no reason to exclude it now (it is, in fact, 100% covered), so it will no longer be excluded. * Scrutinizer Eliminate some newly dead code.
87 lines
4.0 KiB
PHP
87 lines
4.0 KiB
PHP
<?php
|
|
|
|
$config = [];
|
|
|
|
if (PHP_VERSION_ID < 80000) {
|
|
// GdImage not available before PHP8
|
|
$config['parameters']['ignoreErrors'][] = [
|
|
'message' => '~^Method .* has invalid return type GdImage\.$~',
|
|
'path' => __DIR__ . '/src/PhpSpreadsheet/Shared/Drawing.php',
|
|
'count' => 1,
|
|
];
|
|
$config['parameters']['ignoreErrors'][] = [
|
|
'message' => '~^Property .* has unknown class GdImage as its type\.$~',
|
|
'path' => __DIR__ . '/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php',
|
|
'count' => 1,
|
|
];
|
|
$config['parameters']['ignoreErrors'][] = [
|
|
'message' => '~^Method .* has invalid return type GdImage\.$~',
|
|
'path' => __DIR__ . '/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php',
|
|
'count' => 1,
|
|
];
|
|
$config['parameters']['ignoreErrors'][] = [
|
|
'message' => '~^Parameter .* of method .* has invalid type GdImage\.$~',
|
|
'path' => __DIR__ . '/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php',
|
|
'count' => 1,
|
|
];
|
|
$config['parameters']['ignoreErrors'][] = [
|
|
'message' => '~^Class GdImage not found\.$~',
|
|
'path' => __DIR__ . '/src/PhpSpreadsheet/Writer/Xls/Worksheet.php',
|
|
'count' => 1,
|
|
];
|
|
$config['parameters']['ignoreErrors'][] = [
|
|
'message' => '~^Parameter .* of method .* has invalid type GdImage\.$~',
|
|
'path' => __DIR__ . '/src/PhpSpreadsheet/Writer/Xls/Worksheet.php',
|
|
'count' => 1,
|
|
];
|
|
// GdImage with Phpstan 1.9.2
|
|
$config['parameters']['ignoreErrors'][] = [
|
|
'message' => '~Class GdImage not found.*$~',
|
|
'path' => __DIR__ . '/tests/PhpSpreadsheetTests/Worksheet/MemoryDrawingTest.php',
|
|
'count' => 3,
|
|
];
|
|
// Erroneous analysis by Phpstan before PHP8 - 3rd parameter is nullable
|
|
// Fixed for Php7 with Phpstan 1.9.
|
|
//$config['parameters']['ignoreErrors'][] = [
|
|
// 'message' => '#^Parameter \\#3 \\$namespace of method XMLWriter\\:\\:startElementNs\\(\\) expects string, null given\\.$#',
|
|
// 'path' => __DIR__ . '/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php',
|
|
// 'count' => 8,
|
|
//];
|
|
// Erroneous analysis by Phpstan before PHP8 - mb_strlen does not return false
|
|
$config['parameters']['ignoreErrors'][] = [
|
|
'message' => '#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:countCharacters\\(\\) should return int but returns int(<0, max>)?\\|false\\.$#',
|
|
'path' => __DIR__ . '/src/PhpSpreadsheet/Shared/StringHelper.php',
|
|
'count' => 1,
|
|
];
|
|
// New with Phpstan 1.9.2 for Php7 only
|
|
$config['parameters']['ignoreErrors'][] = [
|
|
'message' => '#^Parameter \\#2 \\.\\.\\.\\$args of function array_merge expects array, array<int, mixed>\\|false given.$#',
|
|
'path' => __DIR__ . '/src/PhpSpreadsheet/Calculation/LookupRef/Sort.php',
|
|
'count' => 1,
|
|
];
|
|
$config['parameters']['ignoreErrors'][] = [
|
|
'message' => '#^Parameter \\#1 \\$input of function array_chunk expects array, array<int, float\\|int>\\|false given.$#',
|
|
'path' => __DIR__ . '/src/PhpSpreadsheet/Calculation/MathTrig/MatrixFunctions.php',
|
|
'count' => 1,
|
|
];
|
|
$config['parameters']['ignoreErrors'][] = [
|
|
'message' => '#^Parameter \\#2 \\$array of function array_map expects array, array<int, float|int>\\|false given.$#',
|
|
'path' => __DIR__ . '/src/PhpSpreadsheet/Calculation/MathTrig/Random.php',
|
|
'count' => 1,
|
|
];
|
|
$config['parameters']['ignoreErrors'][] = [
|
|
'message' => '#^Parameter \\#2 \\.\\.\\.\\$args of function array_merge expects array, array<int, mixed>\\|false given.$#',
|
|
'path' => __DIR__ . '/src/PhpSpreadsheet/Calculation/TextData/Text.php',
|
|
'count' => 1,
|
|
];
|
|
} else {
|
|
// Flagged in Php8+ - unsure how to correct code
|
|
$config['parameters']['ignoreErrors'][] = [
|
|
'message' => '#^Binary operation "/" between float and array[|]float[|]int[|]string results in an error.#',
|
|
'path' => __DIR__ . '/src/PhpSpreadsheet/Calculation/MathTrig/Combinations.php',
|
|
'count' => 2,
|
|
];
|
|
}
|
|
|
|
return $config;
|