mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-18 20:00:46 +00:00
5240a23117
PR #2428 reduced the count of Phpstan errors reported under Php8 from 218 to 13. This PR takes care of those 13, which could not necessarily be handled merely by tweaks to the configuration files. The commonest problem was that Phpstan under Php7 thinks date_parse can return an array or false, but, under Php8, it thinks it can return only array. The documentation agrees with the Php7 interpretation, but I have not been able to construct a case, in any release of Php, where date_parse returns false. In case of error, it sets elements 'error' and 'error_count' in the returned array. Code is changed to handle either possibility in a manner of which Phpstan will approve. Other problems are handled through type-hinting.
52 lines
2.2 KiB
PHP
52 lines
2.2 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,
|
|
];
|
|
// Erroneous analysis by Phpstan before PHP8 - 3rd parameter is nullable
|
|
$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\\|false\\.$#',
|
|
'path' => __DIR__ . '/src/PhpSpreadsheet/Shared/StringHelper.php',
|
|
'count' => 1,
|
|
];
|
|
}
|
|
|
|
return $config;
|