phpstan-conditional.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. $config = [];
  3. if (PHP_VERSION_ID < 80000) {
  4. // GdImage not available before PHP8
  5. $config['parameters']['ignoreErrors'][] = [
  6. 'message' => '~^Method .* has invalid return type GdImage\.$~',
  7. 'path' => __DIR__ . '/src/PhpSpreadsheet/Shared/Drawing.php',
  8. 'count' => 1,
  9. ];
  10. $config['parameters']['ignoreErrors'][] = [
  11. 'message' => '~^Property .* has unknown class GdImage as its type\.$~',
  12. 'path' => __DIR__ . '/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php',
  13. 'count' => 1,
  14. ];
  15. $config['parameters']['ignoreErrors'][] = [
  16. 'message' => '~^Method .* has invalid return type GdImage\.$~',
  17. 'path' => __DIR__ . '/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php',
  18. 'count' => 1,
  19. ];
  20. $config['parameters']['ignoreErrors'][] = [
  21. 'message' => '~^Parameter .* of method .* has invalid type GdImage\.$~',
  22. 'path' => __DIR__ . '/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php',
  23. 'count' => 1,
  24. ];
  25. $config['parameters']['ignoreErrors'][] = [
  26. 'message' => '~^Class GdImage not found\.$~',
  27. 'path' => __DIR__ . '/src/PhpSpreadsheet/Writer/Xls/Worksheet.php',
  28. 'count' => 1,
  29. ];
  30. $config['parameters']['ignoreErrors'][] = [
  31. 'message' => '~^Parameter .* of method .* has invalid type GdImage\.$~',
  32. 'path' => __DIR__ . '/src/PhpSpreadsheet/Writer/Xls/Worksheet.php',
  33. 'count' => 1,
  34. ];
  35. // Erroneous analysis by Phpstan before PHP8 - 3rd parameter is nullable
  36. $config['parameters']['ignoreErrors'][] = [
  37. 'message' => '#^Parameter \\#3 \\$namespace of method XMLWriter\\:\\:startElementNs\\(\\) expects string, null given\\.$#',
  38. 'path' => __DIR__ . '/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php',
  39. 'count' => 8,
  40. ];
  41. // Erroneous analysis by Phpstan before PHP8 - mb_strlen does not return false
  42. $config['parameters']['ignoreErrors'][] = [
  43. 'message' => '#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:countCharacters\\(\\) should return int but returns int(<0, max>)?\\|false\\.$#',
  44. 'path' => __DIR__ . '/src/PhpSpreadsheet/Shared/StringHelper.php',
  45. 'count' => 1,
  46. ];
  47. }
  48. return $config;